A structure is a collection of member elements that can be structures, unions, elementary variables and arrays.
The structure variable is a name that can be used to refer to the entire aggregate of data. Unlike an array, however, each member of a structure also has a name, and the attributes of each member can differ. An asterisk can be used as the name of a structure or a member when it will not be referred to. For example, reserved or filler items can be named with an asterisk.
A structure has different levels. The name at level-1 is called a major structure. Names at deeper levels can be minor structures or unions. Names at the deepest level are called elementary names, which can represent an elementary variable or an array variable. Unions are described in Unions.
A structure is described in a DECLARE statement through the use of level-numbers preceding the associated names. Level-numbers must be integers.
A major structure name is declared with the level-number 1. Minor structures, unions, and elementary names are declared with level-numbers greater than 1. A delimiter must separate the level-number and its associated name. For example, the items of a payroll record could be declared as follows:
declare 1 Payroll, /* major structure name */
2 Name, /* minor structure name */
3 Last char(20), /* elementary name */
3 First char(15),
2 Hours,
3 Regular fixed dec(5,2),
3 Overtime fixed dec(5,2),
2 Rate,
3 Regular fixed dec(3,2),
3 Overtime fixed dec(3,2);
In the example, Payroll is the major structure and all other names are members of this structure. Name, Hours, and Rate are minor structures, and all other members are elementary variables. You can refer to the entire structure by the name Payroll, or to portions of the structure by the minor structure names. You can refer to a member by referring to the member name.
Indentation is only for readability. The statement could be written in a continuous string as:
Declare 1 Payroll, 2 Name, 3 Last char(20), . . .
The level-numbers you choose for successively deeper levels need not be consecutive. A minor structure at level n contains all the names with level-numbers greater than n that lie between that minor structure name and the next name with a level-number less than or equal to n.
For example, the following declaration results in exactly the same structure as the declaration in the previous example.
Declare 1 Payroll,
4 Name,
5 Last char(20),
5 First char(15),
3 Hours,
6 Regular fixed dec(5,2),
5 Overtime fixed dec(5,2),
2 Rate,
9 Regular fixed dec(3,2),
9 Overtime fixed dec(3,2);
The description of a major structure is usually terminated by a semicolon terminating the DECLARE statement. It can also be terminated by comma, followed by the declaration of another item.