REDEFINES clause considerations
The topic lists considerations of using the REDEFINES clause.
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.