ILE COBOL Language Reference

REDEFINES Clause Considerations

Data items within an area can be redefined without changing their lengths. For example:

05  NAME-2.
  10  SALARY                  PICTURE XXX.
  10  SO-SEC-NO               PICTURE X(9).
  10  MONTH                   PICTURE XX.
05  NAME-1 REDEFINES NAME-2.
  10  WAGE                    PICTURE XXX.
  10  EMP-NO                  PICTURE X(9).
  10  YEAR                    PICTURE XX.

Data item lengths and types can also be change within a redefined area. For example:

05  NAME-2.
  10  SALARY                  PICTURE XXX.
  10  SO-SEC-NO               PICTURE X(9).
  10  MONTH                   PICTURE XX.
05  NAME-1 REDEFINES NAME-2.
  10  WAGE                    PICTURE 999V999.
  10  EMP-NO                  PICTURE X(6).
  10  YEAR                    PICTURE XX.

When an area is redefined, all descriptions of the area are always in effect; that is, redefinition does not cause any data to be erased and never supersedes a previous description. Thus, if B REDEFINES C has been specified, either of the two procedural statements, MOVE X TO B and MOVE Y TO C, could be executed at any point in the program.

In the first case, the area described as B would assume the value and format of X. In the second case, the same physical area (described now as C) would assume 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 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.

The bit configuration of the DISPLAY value 8 is

1111 0000 1111 1000.

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 -48 is added to A (because C has USAGE COMPUTATIONAL-4) because the bit configuration (truncated to 2 decimal digits) in the storage area has the binary value -48.

The above example demonstrates how the improper use of redefinition may give unexpected or incorrect results.


[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]