Question on redefines in Cobol.

All sort of Mainframes Interview Questions.
Post Reply
Anil Khanna
Registered Member
Posts: 15
Joined: Wed Aug 07, 2013 12:09 am

Question on redefines in Cobol.

Post by Anil Khanna »

Hi All,

I faced these two questions which I could not answer. Can someone please help in knowing:

1. Can we use redefining and redefined vaiables, assume both are numeric, in one operation? Give example.

2. There is this condition:

Code: Select all

01 A PIC X(10) 
01 B REDEFINES A PIC X(20) 
will B gets 20 bytes storage, as A has 10 bytes only ?
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: Question on redefines in Cobol.

Post by Robert Sample »

The Enterprise COBOL Language Reference manual answers many questions. Such as your second question, for example:
| The following example shows that the redefining item, B, can occupy more
| storage than the redefined item, A. The size of storage for the REDEFINED
| clause is determined in number of bytes. Item A occupies 6 bytes of
| storage and item B, a data item of category national, occupies 8 bytes of
| storage.

| 05 A PICTURE X(6).
| 05 B REDEFINES A GLOBAL PICTURE N(4).
as well as your first question:
5.3.13.1 REDEFINES clause considerations

When an area is redefined, all descriptions of the area are always in effect; that is, redefinition does not supersede a previous description. Thus, if B REDEFINES C has been specified, either of the two procedural statements MOVE X TO B or MOVE Y TO C could be executed at any point in the program. In the first case, the area described as B would receive the value and format of X. In the second case, the same physical area (described now as C) would receive the value and format of Y. Note that if the second statement is executed immediately after the first, the value of Y replaces the value of X in the one storage area. The usage of a redefining data item need not be the same as that of a redefined item. This does not, however, cause any change in the format or content of existing data. For example:

05 B PICTURE 99 USAGE DISPLAY VALUE 8.
05 C REDEFINES B PICTURE S99 USAGE COMPUTATIONAL-4.
05 A PICTURE S99 USAGE COMPUTATIONAL-4.


Redefining B does not change the bit configuration of the data in the storage area. Therefore, the following two statements produce different results:

ADD B TO A
ADD C TO A


In the first case, the value 8 is added to A (because B has USAGE DISPLAY). In the second statement, the value -3848 is added to A (because C has USAGE COMPUTATIONAL-4), and the bit configuration of the storage area has the binary value -3848. This example demonstrates how the improper use of redefinition can give unexpected or incorrect results.
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 “Interview Questions.”