LIKE(name)

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:
Attributes such as ALTSEQ(*NONE), NOOPT, ASCEND, CONST and null capability are not inherited from the parameter of LIKE by the item defined. Only the data type, length, decimal positions, and CCSID are inherited.

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.

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

When LIKE is used to define an array, the DIM keyword is still required to define the array dimensions. However, DIM(%elem(array)) can be used to define an array exactly like another array.

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

The following are examples of defining data using the LIKE keyword.

Figure 131. Defining fields LIKE other fields
*.. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 ...+... 8
DName+++++++++++ETDsFrom+++To/L+++IDc.Keywords+++++++++++++++++++++++++++++
D.....................................Keywords+++++++++++++++++++++++++++++
 *
 *  Define a field like another with a length increase of 5 characters.
 *
D  Name           S             20
D  Long_name      S             +5    LIKE(Name)
 *
 *  Define a data structure subfield array with DIM(20) like another
 *  field and initialize each array element with the value *ALL'X'.
 *  Also, declare another subfield of type pointer immediately
 *  following the first subfield. Pointer is implicitly defined
 *  with a length of 16 bytes
 *
D  Struct         DS
D   Dim20                             LIKE(Name) DIM(20) INZ(*ALL'X')
D   Pointer                       *
 *
 *  Define a field which is based on the *LDA.  Take the length and type
 *  of the field from the field 'Name'.
 *
D  Lda_fld        S                    LIKE(Name) DTAARA(*LDA)


[ Top of Page | Previous Page | Next Page | Contents | Index ]