REDIFINE in COBOL with different data-type.

OS/VS COBOL, COBOL II, Enterprise COBOL for z/OS. OpenCOBOL and OOCobol.
Previous topicNext topic

Topic Author
Ashish Mathew
Registered Member
Posts: 50
Joined: Thu Jun 27, 2013 6:17 pm
Zodiac: Scorpio

REDIFINE in COBOL with different data-type.

Post by Ashish Mathew » Sat Oct 14, 2017 8:00 pm

Hi,

If I have a COBOL declaration like this:

Code: Select all

01 WS-A   PIC X(20) VALUES SPACES.
01 WS-B  REDEFINES WS-A PIC 9(10).
and I do a numeric check on the WS- like this:

Code: Select all

IF WS-B IS NUMERIC
   do this
END-IF
Will WS-B be considered as numeric value or not?

Is it a good coding practice?



User avatar

Robert Sample
Global Moderator
Global Moderator
Posts: 1379
Joined: Fri Jun 28, 2013 1:22 am
Location: Dubuque Iowa
Zodiac: Virgo

Re: REDIFINE in COBOL with different data-type.

Post by Robert Sample » Sun Oct 15, 2017 4:11 am

It is very bad practice to do things like your code. REDEFINES variables should be the same length as the REDEFINED variable; it is common for REDEFINES to change PIC X to PIC 9 (or vice versa).

WS-B will be considered numeric (although if you put a period or many other punctuation marks into WS-A, WS-B would not be numeric) since spaces have zero for the second half of each byte.



Previous topicNext topic

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