LIKE

LIKE specifies that the variable being declared has the same structure as the referenced variable. Its format is:

LIKE reference

where reference is a reference to a structure variable.

The variable being declared must be a structure variable. LIKE causes it to have exactly the same members, in name and attributes, as the referenced structure variable. Only the level numbers are changed as needed to adapt to the variable being declared.

In the following example, structure members are duplicated from one declaration to another by way of the LIKE attribute:

DECLARE 1 TEMPLATE BASED, 
   2 NAME CHAR(45),
   2 SALARY FIXED BIN(15), 
   2 EMP_NO FIXED BIN(15);
DECLARE 1 EMPLOYEE_INFO(1000) LIKE TEMPLATE;

Duplication of the members from TEMPLATE expands the declaration of EMPLOYEE_INFO, with the result that the declaration of EMPLOYEE_INFO is equivalent to:

DECLARE 1 EMPLOYEE_INFO(1000), 
   2 NAME CHAR(45),
   2 SALARY FIXED BIN(15),
   2 EMP_NO FIXED BIN(15);

The referenced variable can be a major or a minor structure. It may be qualified, but may not be pointer-qualified. The following restrictions apply to the referenced variable:

The function of the LIKE attribute is similar to that of the TYPE attribute . With LIKE, the storage class of the referenced structure is not carried over to the created structure (same as TYPE). However, neither are the alignment attributes and/or dimensions of the referenced variable carried over (unlike TYPE). Only the alignment and dimensions of substructures and elements of the referenced variable are carried over.

Note: Because the UNALIGNED attribute is not carried forward with LIKE, two LIKE structures could have differing alignment characteristics and sizes because of structure mapping conventions.