ALIAS

Start of changeWhen the ALIAS keyword is specified for an externally-described file, the RPG compiler will use the alias (alternate) names, if present, for the fields associated with the file, and for determining the subfield names for data structures defined with the LIKEREC keyword. When the ALIAS keyword is not specified for the RPG file, or an external field does not have an alias name defined, the RPG compiler will use the standard external field name.End of change

Note: If the alternate name for a particular external field is enclosed in quotes, the standard external field name is used for that field.

Start of changeThe ALIAS keyword is allowed for all externally-described files.End of change

When the PREFIX keyword is specified with the ALIAS keyword, the second parameter of PREFIX, indicating the number of characters to be replaced, does not apply to the alias names. In the following discussion, assume that the file MYFILE has fields XYCUSTNM and XYID_NUM, and the XYCUSTNM field has the alias name CUSTOMER_NAME.

Using the ALIAS keyword for an externally-described file

The DDS specifications for file MYFILE, using the ALIAS keyword for the first field to associate the alias name CUSTOMER_NAME with the CUSTNM field.

A          R CUSTREC
A            CUSTNM        25A         ALIAS(CUSTOMER_NAME)
A            ID_NUM        12P 0>
The source for an RPG program defining a non-qualified file with the ALIAS keyword. The fields for the file are
  • CUSTOMER_NAME (using the ALIAS name)
  • ID_NUM (using the standard name)
Fmyfile    if   e             disk    ALIAS
 /free
     read myfile;
     if customer_name <> *blanks
     and id_num > 0;
       ...
The source for an RPG program defining a qualified file with the ALIAS keyword, and a LIKEREC data structure. The subfields of the data structure are
  • CUSTOMER_NAME (using the ALIAS name)
  • ID_NUM (using the standard name)
Fmyfile    if   e             disk    ALIAS QUALIFIED
D myDs            ds                  LIKEREC(myfile.custRec)
 /free
     read myfile myDs;
     if myDs.customer_name <> *blanks
     and myDs.id_num > 0;
       ...