ContentsIndexPreviousNext

5.7.1.3 REDEFINES clause

The REDEFINES clause allows the same computer memory area to be described by different data items.

General Format

level-number   [ data-name ] REDEFINES prev-data-name
               [ FILLER   ]

Syntax Rules

1. 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.

2. 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.

3. REDEFINES may not be used in a level 01 entry in the File Section.

4. 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).

5. Prev-data-name cannot be qualified. Its reference is unique due to the placement of the REDEFINES clause.

6. Several data items can redefine the same memory area. However, the prev-data-name for all redefinitions must refer to the data-name of the originally defined area.

7. 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.

8. 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.

9. The IS EXTERNAL clause may not be used with the FILLER or REDEFINES clauses.

General Rules

1. Storage allocation for the redefining data item starts at the location of prev-data-name.

2. Storage allocation continues until it defines the number of character positions described by the redefining entry.

3. 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.

4. 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).