Numeric check in Alphanumeric field



Support for OS/VS COBOL, VS COBOL II, COBOL for OS/390 & VM and Enterprise COBOL for z/OS

Numeric check in Alphanumeric field

Postby ssgan » Mon Mar 04, 2013 5:21 pm

Hi,

I am having requirement to check whether Alphanumric variable is having numeric value(just numbers) in it.
Ex- VAR 1 defined as X(4).
It can have value as '1234' OR '12ds'
i need to process based on whether it is having number values or alphanum values.
Can anyone help on this?

thanks,
SSgan
ssgan
 
Posts: 4
Joined: Mon Mar 04, 2013 5:16 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Numeric check in Alphanumeric field

Postby BillyBoyo » Mon Mar 04, 2013 5:33 pm

IF a-far-more-descriptive-name-than-VAR1 NUMERIC
    do some processing for when it is NUMERIC
ELSE
    do some processing for when it is NOT NUMERIC
END-IF
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 265 times

Re: Numeric check in Alphanumeric field

Postby ssgan » Mon Mar 04, 2013 5:53 pm

Hi,

Thanks for your reply Billy
There are chance that i get input as '12 ' where i should treat this is numeric. Numeric check will skip the process here.

Thanks,
Ssgan
ssgan
 
Posts: 4
Joined: Mon Mar 04, 2013 5:16 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Numeric check in Alphanumeric field

Postby BillyBoyo » Mon Mar 04, 2013 5:59 pm

Scroll down the screen a bit and have a look at "Check whether a field is Numeric or not", see if that helps.
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 265 times

Re: Numeric check in Alphanumeric field

Postby Robert Sample » Mon Mar 04, 2013 6:30 pm

Use reference modification (or an array) to check each byte to be spaces or zero through nine (an 88-level might be useful here). If any byte is not one of those 11 eleven characters, it is not numeric. If all bytes are spaces / 0 through 9, then you can use the FUNCTION NUMVAL to convert the PIC X(4) variable to a PIC 9(04) variable and the '12' would be converted as part of that process.
Robert Sample
Global moderator
 
Posts: 3719
Joined: Sat Dec 19, 2009 8:32 pm
Location: Dubuque, Iowa, USA
Has thanked: 1 time
Been thanked: 279 times

Re: Numeric check in Alphanumeric field

Postby BillyBoyo » Mon Mar 04, 2013 7:14 pm

Ensure that you deal with "embedded spaces" however it has been defined to you.

>1  2<
> 1 3<
>1 4 <


as well as
>  15<
>16  <
> 17 <


You would need to be certain about how all those should be treated - as numeric, or not, and what output would be required.
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 265 times


Return to IBM Cobol

 


  • Related topics
    Replies
    Views
    Last post