Data Structures

The ILE RPG compiler allows you to define an area in storage and the layout of the fields, called subfields, within the area. This area in storage is called a data structure.

You define a data structure in free form by specifying the DCL-DS operation code followed by the data structure name and keywords. You define a data structure in fixed form by specifying DS in positions 24 through 25 on a definition specification.

You can use a data structure to:
  • Define the same internal area multiple times using different data formats
  • Define a data structure and its subfields in the same way a record is defined.
  • Define multiple occurrences of a set of data.
  • Group non-contiguous data into contiguous internal storage locations.
  • Operate on all the subfields as a group using the name of the data structure.
  • Operate on an individual subfield using its name.
In addition, there are four special data structures, each with a specific purpose:
  • A data area data structure (identified by the *AUTO parameter of the DTAARA keyword for a free-form definition or a U in position 23 of a fixed-form definition)
  • A file information data structure (identified by the keyword INFDS on a file description specification)
  • A program-status data structure (identified by the PSDS keyword for a free-form definition, or by an S in position 23 of a fixed-form definition)
  • An indicator data structure (identified by the keyword INDDS on a file description specification).

Data structures can be either program-described or externally described, except for indicator data structures, which are program-described only.

One data structure can be defined like another using the LIKEDS keyword.

A program-described data structure is identified by the absence of the EXT or EXTNAME keywords for a free-form definition, or by a blank in position 22 of a fixed-form definition. The subfield definitions for a program-described data structure must immediately follow the data structure definition.

An externally described data structure, identified by the EXT keyword or the EXTNAME keyword for a free-form definition, or by an E in position 22 of a fixed-form definition, has subfield descriptions contained in an externally described file. At compile time, the ILE RPG compiler uses the external name to locate and extract the external description of the data structure subfields. If the EXTNAME keyword is not specified, the name of the data structure is used for the external file name.

Note: The data formats specified for the subfields in the external description are used as the internal formats of the subfields by the compiler. This differs from the way in which externally described files are treated.

An external subfield name can be renamed in the program using the keyword EXTFLD. The keyword PREFIX can be used to add a prefix to the external subfield names that have not been renamed with EXTFLD. Note that the data structure subfields are not affected by the PREFIX keyword specified on a file-description specification even if the file name is the same as the parameter specified in the EXTNAME keyword when defining the data structure using an external file name. Additional subfields can be added to an externally described data structure by specifying program-described subfields immediately after the list of external subfields.

You can also define an externally-described data structure using the LIKEREC keyword

You can control the CCSID of alphanumeric subfields of externally-described data structures by specifying the CCSID(*EXACT) or CCSID(*NOEXACT) keyword on the data structure. If you specify CCSID(*EXACT), the alphanumeric subfields will have the same CCSID as the fields in the file. If you specify CCSID(*NOEXACT), or you do not specify the CCSID keyword for the data structure, the alphanumeric subfields will have the default CCSID for alphanumeric definitions. See CCSID(*EXACT | *NOEXACT) and CCSID(*CHAR : *JOBRUN | *JOBRUNMIX | *UTF8 | *HEX | number) for more information about alphanumeric CCSIDs.