ALIAS

外部記述データ構造に ALIAS キーワードが指定されると、 RPG コンパイラーは、サブフィールドに別名 (代替名) があれば、それを使用します。 データ構造に ALIAS キーワードが指定されない、または外部フィールドに別名が定義されていない場合、 RPG コンパイラーは標準の外部フィールド名を使用します。

別名が使用されていて、サブフィールドの名前を変更する場合には、 EXTFLD キーワードのパラメーターとしてその別名を指定します。 EXTFLD キーワードでは継続がサポートされないため、 1 つのソース指定で名前全体を指定してください。 図 1 は、同じファイルについて定義された、2 つのデータ構造を含む例を示しています。 ALIAS キーワードがコーディングされたデータ構造では、EXTFLD キーワードのパラメーターとして、別名 CUSTOMER_ADDRESS を使用します。 ALIAS キーワードがコーディングされていないデータ構造では、EXTFLD キーワードのパラメーターとして、標準名 CUSTAD を使用します。

注: 特定の外部フィールドの代替名が引用符で囲まれている場合、標準の外部フィールド名がそのフィールドに対して使用されます。
ALIAS キーワードと一緒に PREFIX キーワードを指定した場合、 置換対象文字数を示す、PREFIX の 2 番目のパラメーターは、別名には適用されません。 以下の説明では、外部ファイル MYFILE にフィールド XYCUSTNM と XYID_NUM があり、XYCUSTNM フィールドの別名が CUSTOMER_NAME であることを想定しています。
図 1. 外部記述データ構造に対する ALIAS キーワードの使用
 * The DDS specifications for file MYFILE, using the ALIAS keyword
 * for the first two fields, to associate alias name CUSTOMER_NAME
 * with the CUSTNM field and alias name CUSTOMER_ADDRESS
 * with the CUSTAD field.A          R CUSTREC
A            CUSTNM        25A         ALIAS(CUSTOMER_NAME)
A            CUSTAD        25A         ALIAS(CUSTOMER_ADDRESS)
A            ID_NUM        12P 0

 * The RPG source, using the ALIAS keyword.
 * The customer-address field is renamed to CUST_ADDR
 * for both data structures.D aliasDs       e ds                  ALIAS
D                                     QUALIFIED EXTNAME(myfile)
D   cust_addr   e                     EXTFLD(CUSTOMER_ADDRESS)
D noAliasDs     e ds
D                                     QUALIFIED EXTNAME(myfile)
D   cust_addr   e                     EXTFLD(CUSTAD)
 /free
    // The ALIAS keyword is specified for data structure "aliasDs"
    // so the subfield corresponding to the "CUSTNM" field has
    // the alias name "CUSTOMER_NAME"    aliasDs.customer_name = 'John Smith';
    aliasDs.cust_addr = '123 Mockingbird Lane';
    aliasDs.id_num = 12345;

    // The ALIAS keyword is not specified for data structure
    // "noAliasDs", so the subfield corresponding to the "CUSTNM"
    // field does not use the alias name    noAliasDs.custnm = 'John Smith';
    aliasDs.cust_addr = '123 Mockingbird Lane';
    noAliasDs.id_num = 12345;