ALIAS

When 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.

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

The ALIAS keyword is allowed for all externally-described files.

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.

  • If keyword PREFIX(NEW_) is specified, there is no second parameter, so no characters are replaced for any names. The names used for fields and LIKEREC subfields will be NEW_CUSTOMER_NAME and NEW_XYID_NUM.
  • If keyword PREFIX(NEW_:2) is specified, two characters will be replaced in the names of fields that do not have an alias name. The names used for fields and LIKEREC subfields will be NEW_CUSTOMER_NAME and NEW_ID_NUM. The first two characters, "XY", are replaced in XYID_NUM, but no characters are replaced in CUSTOMER_NAME.
  • If keyword PREFIX('':2) is specified, two characters will be repaced in the names of fields that do not have an alias name. The names used for fields and LIKEREC subfields will be CUSTOMER_NAME and ID_NUM. The first two characters, "XY", are replaced in XYID_NUM, but no characters are replaced in CUSTOMER_NAME.
  • If the first parameter for PREFIX contains a data structure name, for example PREFIX('MYDS.'), the part of the prefix before the dot will be ignored for data structures defined with the LIKEREC keyword.

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;
       ...