The LIKE keyword is used to define an item like an existing one. For information about using LIKE with an object, see LIKE(object-name).
When the LIKE keyword is specified, the item being defined takes on the length and the data format of the item specified as the parameter. Standalone fields, prototypes, parameters, and data-structure subfields may be defined using this keyword. The parameter of LIKE can be a standalone field, a data structure, a data structure subfield, a parameter in a procedure interface definition, or a prototype name. The data type entry (position 40) must be blank.
When LIKE is used to define an item like an array, the DIM keyword is required to define the array dimensions. However, DIM(%ELEM(array)) can be used to define an array with the same dimension as another array.
If the parameter of LIKE is a prototype, then the item being defined will have the same data type as the return value of the prototype. If there is no return value, then an error message is issued.
The length of the item being defined can be adjusted. You specify the length adjustment in the second parameter of the LIKE keyword in free-form definitions, or the Length entry in fixed-form definitions. The length adjust must be specified with either a positive (+) or negative (-) sign.
Use LIKEDS to define a data structure like another data structure, with the same subfields.
The following examples are shown first in free-form and then in fixed-form.
DCL-S Name CHAR(20);
DCL-S Long_name LIKE(Name : +5); 1
DCL-DS Struct;
NameList LIKE(Name) DIM(20) INZ(*ALL'X'); 2
END-DS;
DCL-PR GetBonus LIKE(Salary : -2); 3
Employee_Id INT(10) VALUE;
END-PR;
*.. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 ...+... 8
DName+++++++++++ETDsFrom+++To/L+++IDc.Keywords+++++++++++++++++++++++++++++
D.....................................Keywords+++++++++++++++++++++++++++++
D Name S 20
D Long_name S +5 LIKE(Name) 1
D Struct DS
D NameList LIKE(Name) DIM(20) INZ(*ALL'X') 2
D GetBonus PR -2 LIKE(Salary) 3
D Employee_Id 10I 0 VALUE