Defining typed structures and unions

The DEFINE STRUCTURE statement specifies a named structure or union type.

Read syntax diagramSkip visual syntax diagramDEFINESTRUCTURE1 . structure-type-name UNION,,level minor-structure-nameattribute;

Abbreviation: STRUCT

structure-type-name
Specifies the name given to this structure type. This name cannot have dimensions, although substructures can.
UNION
See UNION attribute.
minor-structure-name
Specifies the name given to a deeper level.
attributes
Specifies attributes for the minor-structure name. Only the following attributes are allowed:
  • The data attributes
  • The INITIAL nondata attribute

Any string lengths, area sizes, or array dimensions specified in a DEFINE STRUCT statement must be restricted expressions.

INITIAL expressions in DEFINE STRUCT statements must be restricted expressions that do not depend on any address value. Therefore, ENTRY, FILE, and LABEL constants must not be used in these INITIAL expressions.

Missing data attributes are supplied with PL/I defaults. If a variable is declared as a typed structure, none of the following attributes are propagated to the members of the typed structure. These attributes are propagated if the variable is declared as an untyped structure.

  • ALIGNED|UNALIGNED
  • ASSIGNABLE|NONASSIGNABLE
  • DIMACROSS
  • NATIVE|NONNATIVE
  • NORMAL|ABNORMAL
  • SUPPRESS
Restrictions:
  • Defined structures must occupy a number of bytes that is a multiple of the structure’s alignment.
  • In a defined structure, the number of bytes before the element with the most stringent alignment must be a multiple of that element's alignment.

For example, if a structure contains an aligned fixed bin(31) field as its most stringently aligned item, the following applies:

  • The structure must occupy a multiple of 4 bytes.
  • There must be a multiple of 4 bytes before the first aligned fixed bin(31) field.

The DEFINE STRUCTURE statement defines a “strong” type. In other words, variables declared with that type can only be assigned to variables (or parameters) having the same type. Typed structures can not be used in data-directed input/output statements.

A DEFINE STRUCTURE statement that merely names the structure to be defined without specifying any of its members defines an "unspecified structure".
  • An unspecified structure cannot be dereferenced, but it can be used to declare a HANDLE which, of course, cannot be dereferenced either.
  • An unspecified structure can also be the subject of a later DEFINE STRUCTURE statement that does specify its members.

Unspecified structure definitions are useful when a structure definition contains a handle to a second structure that also contains a handle to the first structure. For instance, in the following example, the parent structure contains a handle to the child structure, but the child structure also contains a handle to the parent structure.

   define structure 1 child;

   define structure
    1 parent,
      2 first_child   handle child,
      2 parent_data   fixed bin(31);

   define structure
    1 child,
      2 parent        handle parent,
      2 next_child    handle child,
      2 child_data    fixed bin(31);