The REDEFINES clause allows the same computer memory area to be described by different data items. ACUCOBOL-GT extends ANSI85
COBOL by allowing a REDEFINES phrase to reference an item that is itself a redefinition of an area.
General Format
level-number [ data-name ] REDEFINES prev-data-name
[ FILLER ]
Syntax Rules
- The
level-number,
data-name, and FILLER phrases in the General Format are not actually part of the REDEFINE clause. They are included for clarity.
- The level-numbers of the subject of a REDEFINES clause and
prev-data-name must be the same. They may not be 66 or 88.
- REDEFINES is allowed in a level 01 entry in the File Section, but it will generate a warning message.
- The number of character positions described by
prev-data-name need not be the same as the number of character positions in the subject of the REDEFINES clause. The compiler generates
a warning, however, if the number of character positions is greater in the subject of the REDEFINES clause than in
prev-data-name and the level-number of the two data items is not 01 or 77 (this case is not allowed under ANSI COBOL).
- The data item being redefined may be qualified, but any qualification specified is ignored.
Example:
01 MY-FILLER REDEFINES THIS-FIELD OF THIS-GROUP.
The phrase in the example compiles, but the qualification
OF THIS-GROUP is ignored.
- Several data items can redefine the same memory area.
- No entry with a level-number lower than that of
prev-data-name can occur between the data description entry for
prev-data-name and the redefinition.
- All entries redefining the storage area of a data item must immediately follow the entries describing that data item. No intervening
entries that define additional storage may appear.
- The IS EXTERNAL clause may not be used with the FILLER or REDEFINES clauses.
General Rules
- Storage allocation for the redefining data item starts at the location of
prev-data-name.
- Storage allocation continues until it defines the number of character positions described by the redefining entry.
- prev-data-name may contain the OCCURS clause, although this is not compatible with ANSI COBOL. If such a situation exists, the compiler
will return a
caution warning indicating a non-ANSI construct. Cautions are shown only when you compile with the
-a option. When you REDEFINE a data item with an OCCURS clause, the redefining item starts at the same memory location as the
first occurrence of the redefined item.
- In large model programs, certain REDEFINES could cause VALUE clauses to be lost. This happens when the VALUEs are set in a
data item that is not a large data item, and then that data item is redefined as a large data item. When that occurs, the
compiler detects the situation and issues a warning message:
Warning: Large redefines of a regular variable with a
value: desc2 redefines desc1
When you see this warning message, you should modify your COBOL program to add FILLER to the first data item in order to
make it a large data item. For example, the following code:
01 small-group-item.
03 small-data-item pic x(100) value "this is a test".
01 large-group-item redefines small-group-item.
03 free-form-text pic x(100) occurs 1000 times.
will compile, but the value of small-data-item will be spaces when the program starts. To work around this, add:
03 filler pic x(65000).
to the small-group-item after the small-data-item. The resulting code should look like this:
01 small-group-item.
03 small-data-item pic x(100) value "this is a test".
03 filler pic x(65000).