Page 1 of 1

REDIFINE in COBOL with different data-type.

Posted: Sat Oct 14, 2017 8:00 pm
by Ashish Mathew
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?

Re: REDIFINE in COBOL with different data-type.

Posted: Sun Oct 15, 2017 4:11 am
by Robert Sample
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.