A member of a structure or a union can be referred to by its name alone if it is unique. If another member has the same name, whether at the same or different level, ambiguity occurs. Where ambiguity occurs, a qualified reference is required to uniquely identify the correct member.
A qualified reference is a member name that is qualified with one or more names of parent members connected by periods. (See the qualified reference syntax in Expressions and references.) Blanks can appear surrounding the period.
The qualification must follow the order of levels. That is, the name at the highest level must appear first, with the name at the deepest level appearing last.
While the level-1 structure or union name must be unique within the block scope, member names need not be unique as long as they do not appear at same logical level within their most immediate parent. A qualified name must be used only so far as necessary to make a reference of the same structure unique within the block in which it appears. In the following example, the value of x.y (19) is displayed, not the value (17).
dcl Y fixed init(17); begin; dcl 1 X, 2 Y fixed init(19); display( Y ); end;
A reference is always taken to apply to the declared name in the innermost block containing the reference.
The following examples illustrate both ambiguous and unambiguous references. In the following example, A.C refers to C in the inner block; D.E refers to E in the outer block.
declare 1 A, 2 C, 2 D, 3 E;
begin;
declare 1 A, 2 B, 3 C, 3 E;
A.C = D.E;
In the following example, D has been declared twice. A reference to A.D refers to the second D, because A.D is a complete qualification of only the second D. The first D is referred to as A.C.D.
declare 1 A,
2 B,
2 C,
3 D,
2 D;
In the following example, a reference to A.C is ambiguous because neither C can be completely qualified by this reference.
declare 1 A,
2 B,
3 C,
2 D,
3 C;
In the following example, a reference to A refers to the first A, A.A to the second A, and A.A.A to the third A.
declare 1 A,
2 A,
3 A;
In the following example, a reference to X refers to the first DECLARE statement. A reference to Y.Z is ambiguous. Y.Y.Z refers to the second Z, and Y.X.Z refers to the first Z.
declare X;
declare 1 Y,
2 X,
3 Z,
3 A,
2 Y,
3 Z,
3 A;
For more information about name qualification, refer to Scope of declarations.