REDIFINE in COBOL with different data-type.

OS/VS COBOL, COBOL II, Enterprise COBOL for z/OS. OpenCOBOL and OOCobol.
Post Reply
Ashish Mathew
Registered Member
Posts: 50
Joined: Thu Jun 27, 2013 6:17 pm

REDIFINE in COBOL with different data-type.

Post 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?
User avatar
Robert Sample
Global Moderator
Global Moderator
Posts: 1895
Joined: Fri Jun 28, 2013 1:22 am
Location: Dubuque Iowa
United States of America

Re: REDIFINE in COBOL with different data-type.

Post 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.
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.”