FORTRAN 77 Language Reference

Substructure Declaration

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:

Record within a Structure

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.

Example: Define structure SALE using previously defined record PRODUCT:


	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/.

Structure within a Structure

You can nest a declaration within a declaration.

Example: If /PRODUCT/ is not declared previously, then you can declare it within the declaration of SALE:


	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.

Field Reference in Substructures

You can refer to fields within substructures.

Example: Refer to fields of substructures (PRODUCT and SALE, from the previous examples, are defined in the current program unit):


	... 
	RECORD /SALE/ JAPAN 
	... 
	N = JAPAN.QUANTITY 
	I = JAPAN.ITEM.ID 
	... 

Rules and Restrictions for Substructures

Note the following: