COBOL REDEFINE Tutorial |
Another important statement/feature of COBOL in REDEFINES clause. The Redefines clause lets you define a
field in storage in two or more ways.
When used, this clause must have the same
level number as the data item it is redefining and it must come right after
that item.
The REDEFINES clause allows you to use different data description entries to describe the same computer storage area.
Always remember, the definition and the redefinition
both refer to the same bytes of storage, you can code a Value clause only on
the original definition.
Syntax :
01-49 data-name-1 REDEFINES data-name-2
Example 1: A Redefines clause that
redefines a date field
05 WS-TDY-DTE PIC 9(08).
05 WS-TDY-DTE-X REDEFINES WS-TDY-DTE.
10 TDY-YR PIC 9(04).
10 TDY-MNTH PIC 9(02).
10 TDY-DAY PIC 9(02).
Example 2 : A Redefines clause that
redefines a print field
05 WS-CHG-PERNT PIC ZZ9.9-.
05 WS-CHG-PERNT-X REDEFINES WS-CHG-PERNT
PIC X(6).
Example 3 : A Redefines clause that redefines alphanumeric with numeric.
05 WS-EMP-REC PIC X(20).
05 WS-SAL-AMT REDEFINES WS-EMP-REC.
10 WS-EMP-SALE PIC 9(05)v99.
10 WS-EMP-TAX PIC 9(02)v99.
Rule :
- Level number, data-name-1, and FILLER are not part of the REDEFINES clause itself and are included in the format only for clarity.
- Level-numbers of data-name-1 and data-name-2 must be identical and must not be level 66 or level 88.
- Data-name-1, FILLER identifies an alternate description for the same area and is the redefining item or the REDEFINES subject.
- Data description entry for the redefined item cannot contain an OCCURS clause.
- More than one redefinition of the same storage area is permitted. The entries giving the new descriptions of the storage area must immediately follow the description of the redefined area without intervening entries that define new character positions.
- Multiple redefinitions must all use the data-name of the original entry that defined this storage area.
- Redefining entry (identified by data-name-1) and any subordinate entries, must not contain any VALUE clauses.
No comments:
Post a Comment