The LIKEREC keyword declares a data structure whose subfields are taken from an externally described record format already known to the program through a file declaration. Unlike EXTNAME (which names an external file resolved from a .pf or the catalog), LIKEREC names a record format - its fields come from the file that declares that format.
DCL-F CURRATE DISK KEYED USAGE(*INPUT); // record format CURRATER
DCL-DS recAll LIKEREC(CURRATER:*ALL); // all fields of the record
DCL-DS recKey LIKEREC(CURRATER:*KEY); // only the key fields
recAll.FROMCNTRY = 'USD';
recAll.TOCNTRY = 'EUR';
recAll.RATE = 1.2345;
A LIKEREC data structure is automatically QUALIFIED - subfields are reached with dot notation (recAll.FROMCNTRY). The first argument is the record-format name (the internal name when the format was renamed). The optional second argument is a field-set selector:
| Selector | Imported fields |
|---|---|
*ALL |
Every field in the record format. |
*INPUT |
Input-capable fields (the default when the selector is omitted). |
*OUTPUT |
Output-capable fields. |
*KEY |
Only the key fields, in key order. |
Field-set selector behavior mirrors EXTNAME: for a physical file every field is both input- and output-capable, so *ALL, *INPUT, *OUTPUT, and the default all import the full field list, while *KEY imports only the key fields. Referencing a non-key field on a *KEY data structure is an error, since that field is not part of the structure.
LIKEREC works in both free-format DCL-DS and fixed-format D-spec declarations:
D recAll DS LikeRec(CURRATER:*All)
D recKey DS LikeRec(CURRATER:*Key)
An invalid field-set selector (anything other than *ALL, *INPUT, *OUTPUT, or *KEY) is rejected with TRN1015. Unlike EXTNAME, PREFIX is not allowed with LIKEREC - the compiler reports TRN1016. To rename a record-format's fields, define the data structure with EXTNAME(file:format) and PREFIX(...) instead.