Supported RPG Features

The LIKEDS keyword declares a data structure with the same subfield layout as an existing data structure:

DCL-DS AddressTemplate QUALIFIED;
  Street CHAR(50);
  City   CHAR(30);
  Zip    CHAR(10);
END-DS;

DCL-DS ShipAddr LIKEDS(AddressTemplate);
END-DS;

ShipAddr.Street = '123 Main St';
ShipAddr.City   = 'Springfield';

LIKEDS data structures are automatically QUALIFIED - subfields must be accessed with dot notation (ShipAddr.Street, not bare Street). Each LIKEDS instance has independent storage; modifying one does not affect the source or other copies.

The referenced structure may be declared anywhere in the module, including below the structure that names it, and chains of LIKEDS resolve in either order. A LIKEDS that names a structure declared nowhere is an error, as is a cycle (A LIKEDS(B) with B LIKEDS(A)).

Note that field-level LIKE does not share this rule: a subfield declared LIKE another subfield of the same structure must come after the field it references, matching IBM. Only structure-level LIKEDS may look forward.

A LIKEDS data structure may be declared as an array with DIM. Each element carries the template's subfields; an element's subfield is read and written by indexing the structure before the dot - arr(index).subfield:

DCL-DS Line LIKEDS(LineTemplate) DIM(10);

Line(1).Item = 'WIDGET';
Line(1).Qty  = 5;
Total = Line(1).Qty;   // reads element 1's Qty subfield