get the length of the numeric values, alphabets from the COBOL variable

OS/VS COBOL, COBOL II, Enterprise COBOL for z/OS. OpenCOBOL and OOCobol.
Post Reply
pinball
Registered Member
Posts: 32
Joined: Sun Jul 07, 2013 1:28 am
India

get the length of the numeric values, alphabets from the COBOL variable

Post by pinball »

Hi,

I have variable like below

01 ws-a pic x(30) value 'abcd234567@#₹....'

I want to get the length of the numeric values, alphabets
 
User avatar
zum13
Registered Member
Posts: 97
Joined: Thu May 04, 2023 12:58 am

Re: get the length of the numeric values, alphabets from the COBOL variable

Post by zum13 »

Hello.

There is a "LENGTH" function and the "LENGTH OF" keywords, but these only provide the length of the field and not the length of the data within. This came up fairly recently, so you'll hopefully find what you need in this thread: viewtopic.php?p=36828#p36828
pinball
Registered Member
Posts: 32
Joined: Sun Jul 07, 2013 1:28 am
India

Re: get the length of the numeric values, alphabets from the COBOL variable

Post by pinball »

Thanks again zum13, that thread is helpful. How can we know that the read character is numeral or alphabet, once the length is known?
User avatar
zum13
Registered Member
Posts: 97
Joined: Thu May 04, 2023 12:58 am

Re: get the length of the numeric values, alphabets from the COBOL variable

Post by zum13 »

An "IS NUMERIC" check will do the job, for example:

Code: Select all

           IF WA-STRING(1:WA-LENGTH) IS NUMERIC
              do stuff here
           END-IF
 
Post Reply

Create an account or sign in to join the discussion

You need to be a member in order to post a reply

Create an account

Not a member? register to join our community
Members can start their own topics & subscribe to topics
It’s free and only takes a minute

Register

Sign in

Return to “IBM COBOL, GnuCOBOL (OpenCOBOL), OOCobol.”