Function
The REDEFINES clause allows the programmer to define different data description entries for the same area of computer storage.
Format
level-number
[data-name-1 | FILLER] REDEFINES data-name-2
(The level number, data-name-1 and FILLER are not part of the REDEFINES clause, and are shown here only for clarity.)
Syntax rules
The REDEFINES clause, when used, must immediately follow data-name-1.
The level numbers of data-name-1 and data-name-2 must be identical, but must not be 66 or 88.
The length of the data item of data-name-1 must be less than or equal to the length of the data item of data-name-2, if the associated level-number is not equal to 01. There is no such restriction in effect at level 01.
Data-name-2 may be qualified but not indexed or subscripted.
The data description entry for data-name-2 must not contain an OCCURS clause; however, data-name-2 may be subordinate to a data item which contains an OCCURS clause. In this case, the reference to data-name-2 in the REDEFINES clause must not be indexed or subscripted. A data item that is subordinate to data-name-2 may contain an OCCURS clause without the DEPENDING ON phrase (see "OCCURS clause").
Data-name-1 or any data item subordinate to data-name-1 may contain an OCCURS clause without the DEPENDING ON phrase. If data-name-1 contains an OCCURS clause, the size of data-name-1 is calculated by multiplying the length of one table element by the number of occurrences of the table element.
The REDEFINES clause must not appear in 01-level entries in the FILE SECTION (implicit redefinition is provided there automatically at 01-level).
Multiple redefinitions of the storage area are permitted but must all refer to the data-name supplied in the original definition.
Except for condition-name entries, the entries giving a new description of a storage area must not contain a VALUE clause.
No entries having level numbers numerically lower than that of data-name-1 and data-name-2 may occur between the descriptions of data-name-1 and data-name-2.
Data entries having level numbers numerically equal to that of data-name-1 and data-name-2 may only occur between data-name-1 and data-name-2 if they also contain a REDEFINES clause.The REDEFINES clause may be specified for an item subordinate to a redefined item, or for a data item which is subordinate to an item containing a REDEFINES clause.
The REDEFINES clause may not be located within a type description entry.
The REDEFINES clause may not be specified for data of the class "object" or "pointer" or for group items which contain such data.
data-name-2 may not be of the class "object" or "pointer" in a group item which contains such data or is a strongly typed group item.
data-name-2 may not be ANY LENGTH clause.
The REDEFINES clause may not be specified in the record description entry of a file with organization XML.
General rules
data-name-1 is the name of the data area associated with the redefinition.
data-name-2 is the name of the original definition of the data area to be redefined.Redefinition starts at data-name-2 and ends when a level number less than or equal to that of data-name-2 is encountered.
When an area is redefined, all descriptions of that area remain in effect. For example, if A and B are two separate data items sharing the same storage area, the procedure statements MOVE ALPHA TO A or MOVE BETA TO B could be executed at any point in the program. In the first case, ALPHA would be moved to A and would take the form specified by the description of A. In the second case, BETA would be moved to the same physical area and would take the form specified by the description of B. If both MOVE statements were executed successively in the order specified, the value BETA would overlay the value ALPHA; however, redefinition of an area does not erase any data and does not supersede a previous description.
Moving a data item from A to B when B is a redefinition of A amounts to moving an item to itself, and the result of such a move is unpredictable. The same is true of the opposite type of move; that is, moving A to B when A redefines B.
The use of data items defined by the PICTURE and USAGE clauses within an area can be redefined. Altering the use of an area by the REDEFINES clause does not, however, change any existing data.
When the SYNCHRONIZED clause is specified in a data entry that is redefining a previous data entry, the user should ensure that the area being redefined begins on the proper boundary: halfword, fullword, or doubleword.
Example 7-21
02 ALPHA. 03 A-1 PICTURE X(3). 03 A-2 PICTURE X(2). 02 BETA REDEFINES ALPHA PICTURE 9(5). 02 GAMMA.
BETA is data-name-1; ALPHA is data-name-2. BETA redefines the area assigned to ALPHA (that is, the area occupied by A-1 and A-2). Redefinition starts at BETA and ends at the next level number 02 (the number preceding GAMMA).
Example 7-22
(Multiple redefinitions)
02 ALPHA PICTURE 9(3). 02 BETA REDEFINES ALPHA PICTURE X(3). 02 GAMMA REDEFINES ALPHA PICTURE A(3).
Example 7-23
01 SAMPLE-AREA-1. 02 FIRST-DEFINITION PICTURE 99 VALUE 12. 02 SECOND-DEFINITION REDEFINES FIRST-DEFINITION USAGE COMPUTATIONAL PICTURE S9(4).
In this example, FIRST-DEFINITION is a 2-byte unsigned external decimal number with the value 12. This means that the contents of the two bytes in hexadecimal is X’F1F2’. SECOND-DEFINITION is also a number, and occupies the same two bytes; but it does not have the value 12. The data in these two bytes (X’F1F2’) is unchanged by the redefinition; and, since SECOND-DEFINITION is a signed, binary number, this data has the value -
3598.
Example 7-24
01 SAMPLE-AREA-2. 02 FIRST-DEFINITION. 03 ALPHA PICTURE X(3). 03 BETA PICTURE X(5). 03 GAMMA REDEFINES BETA PICTURE 9(5). 03 FILLER PICTURE X(10). 02 SECOND-DEFINITION REDEFINES FIRST-DEFINITION PICTURE X(18).
In this example, one of the items subordinate to FIRST-DEFINITION is redefined: GAMMA REDEFINES BETA. This is permitted, and is not blocked by the fact that FIRST-DEFINITION is itself later redefined by SECOND-DEFINITION.
Example 7-25
01 SAMPLE-AREA-3. 02 FIRST-DEFINITION PICTURE S9(7). 02 SECOND-DEFINITION REDEFINES FIRST-DEFINITION. 03 A-1 PICTURE A. 03 N-1 REDEFINES A-1 PICTURE 9. 03 FILLER PICTURE X(6)
In this example, one of the data items subordinate to SECOND-DEFINITION is redefined; N-1 REDEFINES A-1. This is permitted, and is not blocked by the fact that SECOND-DEFINITION itself is a redefinition.