The LIKE attribute specifies that the name that is declared has an organization that is logically the same as the referenced structure or union, the object of the LIKE attribute.
The object variable's member names and their attributes, including the dimension attribute, are effectively copied and become members of the name being declared. If necessary, the level-numbers of the copied members are automatically adjusted. The object variable name and its attributes, including the dimension attribute, are ignored.
>>-LIKE--object-variable---------------------------------------><
The objects in all LIKE attributes are associated with declared names before any LIKE attributes are expanded.
New members cannot be added to the created structure or union. Any level-number that immediately follows the object variable in the LIKE attribute must be equal to or less than the level-number of the name with the LIKE attribute.
dcl
1 name,
2 first char(20) var,
2 middle char(10) var,
2 last char(30) var;
dcl func entry( like name );
The declare
for the entry "func"would be the same as this
longer declare:dcl func entry( 1, 2 char(20) var, 2 char(10) var, 2 char(30) var );
dcl
1 A(10) aligned static,
2 B bit(4),
2 C bit(4),
1 X like A;
dcl
1 X,
2 B bit(4),
2 C bit(4);
Notice that the dimension (DIM(10)), ALIGNED, and STATIC attributes are not copied as part of the LIKE expansion.
The LIKE attribute is expanded before the defaults are applied and before the ALIGNED and UNALIGNED attributes are applied to the contained elements of the LIKE object variable. However, the LIKE attribute is expanded only after all LIKE attributes have been resolved.
Consider the following declarations:
declare 1 A,
2 C,
3 E(3) union,
5 E1,
5 E2,
3 F;
declare 1 B(10) union,
2 C, 3 G, 3 H,
2 D;
begin;
declare 1 C like B;
declare 1 D(2),
5 BB like A.C;
end;
dcl
1 C, /* DIM and UNION not copied. */
2 C, 3 G, 3 H,
2 D;
dcl 1 D(2),
5 BB,
6 E(3) union, /* DIM(3) and UNION copied. */
7 E1, /* Note adjusted level-numbers. */
7 E2,
6 F;
dcl 1 a, 2 a1 fixed bin;
dcl 1 b, 2 b1 like a;
dcl 1 c, 2 c1 like b;
dcl 1 d, 2 d1 fixed bin;
dcl 1 e like d;
dcl 1 aa(30)
,5 aa1 char( 5)
,5 aa2 fixed bin(31)
,5 aa3_array(30)
,7 aa3_1 fixed dec(15,2)
,7 aa3_2 fixed dec(15,2)
,7 aa3_3 fixed dec(11,4)
,7 aa3_4 fixed dec(7,3)
;
dcl bb like aa;
dcl cc like aa3_array;
declare 1 A like C,
1 B,
2 C,
3 D,
3 E like X,
2 F,
1 X,
2 Y,
2 Z;
declare 1 B,
2 C,
3 D,
3 E,
2 F,
1 G like B;
1 A like G.C,