LIKE(name {: length-adjustment})

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.

This keyword is similar to the *LIKE DEFINE operation code (see *LIKE DEFINE). However, it differs from *LIKE DEFINE in that the defined data takes on the data format and CCSID as well as the length.
Note: Start of changeAttributes such as ALTSEQ(*NONE), NOOPT, ASCEND, DESCEND, CONST, dimension and null capability are not inherited from the parameter of LIKE by the item defined. Only the data type, length, format, decimal positions, and CCSID are inherited.End of change

Start of changeWhen 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.End of change

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.

Start of changeThe 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.End of change

Here are some considerations for using the LIKE keyword with different data types:

Use LIKEDS to define a data structure like another data structure, with the same subfields.

Examples of defining data using the LIKE keyword

The following examples are shown first in free-form and then in fixed-form.

  1. Field Long_name is defined like field Name with a length increase of 5 characters.
  2. Subfield array NameList is defined like field Name. Each array element is initialized with the value *ALL'X'.
  3. Prototype GetBonus is defined like field Salary with a length decrease of 2 digits.
Start of change
Figure 1. Defining fields LIKE other fields in Free 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 

 DCL-PR GetBonus LIKE(Salary : -2);  3 
    Employee_Id INT(10) VALUE;
End of change Start of change
Figure 2. Defining fields LIKE other fields in Fixed Form
*.. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 ...+... 8
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
End of change