Examples of Redefines

The first example involves redefining an input record. Here each record represents a transaction. We have several kinds of transactions. The program will read from the file and then inspect In-Tran-Code to know which kind of transaction is involved.

       01  Input-Record.
           05  In-Key-Field                 Pic 9(6).
           05  In-Tran-Code                 Pic X.
           05  In-Data.                     Pic X(18).
           05  In-Add-Tran Redefines In-Data.
               10  In-Add-Field1            Pic X.
               10  In-Add-Field2            Pic 9.
               10  In-Add-Field3            Pic X(10).
               10  In-Add-Field4            Pic 9(6).
           05  In-Alter-Tran Redefines In-Data.
               10  In-Alter-Code            Pic 9.
               10  In-Alter-Data            Pic X(17).
               10  In-Alter-1 Redefines In-Alter-Data.
                   15  In-Alter-Field1      Pic 9(3).
                   15                       Pic X(14).
               10  In-Alter-2 Redefines In-Alter-Data.
                   15  In-Alter-Field2      Pic 9(8).
                   15                       Pic X(9).
               10  In-Alter-3 Redefines In-Alter-Data.
                   15  In-Alter-Field3      Pic X(10).
                   15                       Pic X(7).
           05  Delete-Tran Redefines In-Data.
               10                           Pic X(18).

A data item can Redefine a preceding item at the same level.

The next example involves defining a table already loaded with information. For good measure, it is redefined twice, once with subscripts and once with indexes.

       01  Season-Name-Data.
           05                               Pic X(6) Value 'Spring'.
           05                               Pic X(6) Value 'Summer'.
           05                               Pic X(6) Value 'Autumn'.
           05                               Pic X(6) Value 'Winter'.

       01  Season-Name-Table                Redefines Season-Name-Data.
           05  Season-Name                  Occurs 4 times
                                            Pic X(6).

       01  Season-Name-Table-Indexed        Redefines Season-Name-Data.
           05  Name-of-Season               Occurs 4 times
                                            Indexed by S-N-Index
                                            Pic X(6).