Defines the organization of the structure and the names of members at each level of the structure.
Each declaration is:
level identifier[(bound-pair)][(,…bound-pair)][attribute…]
or
level(declaration)[,…(declaration)][(bound-pair)][(,…bound-pair)][attribute…]
DECLARE 1 PAYROLL, 2 NAME, 3 LAST CHARACTER(70) VARYING, 3 FIRST CHARACTER(70) VARYING, 2 SALARY FIXED DECIMAL(6,2);
The following statement declares a structure named PAYROLL, whose last name can be accessed with a qualified reference:
PAYROLL.NAME.LAST = 'JONES';
Since the last and first names have the same attributes, the same structure can be declared as follows:
DECLARE 1 PAYROLL, 2 NAME, 3 (LAST,FIRST) CHARACTER(70) VARYING 2 SALARY FIXED DECIMAL(6,2);
The following example shows a declaration containing the UNION attribute.
DECLARE 1 CONSUMER_INFO, . . . 3 PHONE_DATA UNION, 4 PHONE_NUMBER CHARACTER (13), 4 ELEMENTS, 5 LEFT_PAREN CHARACTER (1), 5 AREA_CODE CHARACTER (3), 5 RIGHT_PAREN CHARACTER (1), 5 EXCHANGE CHARACTER (3), 5 HYPHEN CHARACTER (1), 5 ACTUAL_NUMBER CHARACTER (4), 3 ADDRESS_DATA, . . .
In this example, the UNION attribute associated with the declaration of PHONE_DATA's immediate members (PHONE_NUMBER and ELEMENTS) share the same storage, so any change to PHONE NUMBER also changes one or more members of ELEMENTS. Conversely, changing a member of ELEMENTS also changes PHONE_NUMBER. However, the UNION attribute does not apply to the members of ADDRESS_DATA, because these members are not immediate members of PHONE_DATA. The members of ADDRESS_DATA occupy separate storage, as is typical for structure members.
Description
The declaration of a structure defines the organization of the structure and the names of members at each level of the structure. Each declaration specifies a member of the structure and must be preceded by a level-number. A single variable can be declared at a particular level, or the level can contain one or more complete declarations, including declarations of arrays or other structures. The major structure name is declared as structure level 1. Minor members must be declared with level-numbers greater than 1.