A structure can have a field that is also a structure. Such a field is called a substructure. You can declare a substructure in one of two ways:
A RECORD declaration within a structure declaration
A structure declaration within a structure declaration (nesting)
A nested structure declaration is one that is contained within either a structure declaration or a union declaration. You can use a previously defined record within a structure declaration.
STRUCTURE /SALE/ CHARACTER*32 BUYER INTEGER*2 QUANTITY RECORD /PRODUCT/ ITEM END STRUCTURE
In the above example, the structure SALE contains three fields, BUYER, QUANTITY, and ITEM, where ITEM is a record with the structure, /PRODUCT/.
You can nest a declaration within a declaration.
STRUCTURE /SALE/ CHARACTER*32 BUYER INTEGER*2 QUANTITY STRUCTURE /PRODUCT/ ITEM INTEGER*4 ID CHARACTER*16 NAME CHARACTER*8 MODEL REAL*4 COST REAL*4 PRICE END STRUCTURE END STRUCTURE
Here, the structure SALE still contains the same three fields as in the prior example: BUYER, QUANTITY, and ITEM. The field ITEM is an example of a field-list (in this case, a single-element list), as defined under "Structure Declaration."
The size and complexity of the various structures determine which style of substructure declaration is best to use in a given situation.
You can refer to fields within substructures.
... RECORD /SALE/ JAPAN ... N = JAPAN.QUANTITY I = JAPAN.ITEM.ID ...
Note the following:
You must define at least one field name for any substructure.
No two fields at the same nesting level can have the same name. Fields at different levels of a structure can have the same name; however, doing so might be questionable programming practice.
You can use the pseudo-name, %FILL, to align fields in a record, and create an unnamed empty field.
You must not include a structure as a substructure of itself, at any level of nesting.