The DEFINED attribute specifies that the declared variable is associated with some or all of the storage associated with the designated base variable.
The UNION attribute allows you to achieve the same end in a much cleaner manner and also allows variables with different attributes and precisions to be overlaid. Also, while the DEFINED attribute guarantees that access through defined or base variables is reflected in all defined variables, in a union only one member of the union is valid at any given time. For syntax information on the UNION attribute, refer to UNION attribute.
|
Abbreviations: DEF for DEFINED, POS for POSITION
If the base variable is a data aggregate, a defined variable can comprise all the data or only a specified part of it.
The defined variable does not inherit any attributes from the base variable. The defined variable must be INTERNAL and a level-1 identifier. It can have the dimension attribute. It cannot be INITIAL, AUTOMATIC, BASED, CONTROLLED, STATIC, or a parameter.
There are three types of defining: simple, iSUB and string overlay.
The type of defining in effect is determined as follows:
If the POSITION attribute is specified, the base variable must not contain iSUB references.
A base variable and a defined variable match if the base variable when passed as an argument matches a parameter which has the attributes of the defined variable (except for the DEFINED attribute). For this purpose, the parameter is assumed to have all array bounds, string lengths, and area sizes specified by asterisks.
For simple and iSUB defining, a PICTURE attribute can only be matched by a PICTURE attribute that is identical except for repetition factors. For a reference to specify a valid base variable in string overlay defining, the reference must be in connected storage. You can override the matching rule completely, but this can cause unwanted side effects within your program.
The values specified or derived for any array bounds, string lengths, or area sizes in a defined variable do not always have to match those of the base variable. However, the defined variable must be able to fit into the corresponding base array, string, or area.
In references to defined data, the STRINGRANGE, SUBSCRIPTRANGE, and STRINGSIZE conditions are raised for the array bounds and string lengths of the defined variable, not the base variable.
The determination of values and the interpretation of names occurs in the following sequence:
If the defined variable is a structure or union containing any elements which are unaligned nonvarying BIT, then all array bounds and string lengths in the defined variable must be specified as constants.
If the defined variable has the BIT attribute, unpredictable results can occur under the following conditions: