COBOL Manual for TNS/E Programs (H06.03+)

Data Division
HP COBOL Manual for TNS/E Programs520347-003
7-48
REDEFINES Clause
REDEFINES Clause
The REDEFINES clause enables you to describe the same computer storage area in
more than one way. This can be quite valuable for tasks such as input data validation,
when tests require different descriptions of the data. It is also convenient when some
portions of a record are constant, while other parts vary.
data-name-2
is the name of the existing data item that is being redefined as data-name-1.
In Example 7-11, the two records RECORD-IN and RECORD-TOTAL share the same
storage space, but their fields are different.
Usage Considerations:
Determining Size of Shared Storage Area
When the redefined item is a record item and one or more redefinitions specify a
different number of character positions than the redefined item (either greater or
lesser), the size of the shared storage area is determined by the requirements of
the largest associated record item.
Elementary items or Data Structures Can Be Redefined
You can describe an elementary data item and follow that description with a
redefinition entry. You can also describe a data structure and follow that description
first with descriptions of its component elementary items (with numerically higher
level numbers), then with a redefinition entry that redefines the data structure.
Redefinition continues until the appearance of a level number less than or equal to
that of the data-name being redefined (or the ending of the current section of the
Data Division).
Example 7-11. REDEFINES Clause
WORKING-STORAGE SECTION.
01 RECORD-IN.
05 RECORD-CODE PIC 9.
05 RECORD-DETAIL PIC X(30).
05 RECORD-SUBTOTAL PIC 9(3)V99.
01 RECORD-TOTAL REDEFINES RECORD-IN.
05 TOTAL-1 PIC 9(5)V99.
05 TOTAL-2 PIC 9(5)V99.
05 TOTAL-3 PIC 9(5)V99.
05 TOTAL-4 PIC 9(5)V99.
05 TOTAL-5 PIC 9(6)V99.
REDEFINES
data-name-2
VST102.vsd