EXTFILE(filename | *EXTDESC)

The EXTFILE keyword specifies which file, in which library, is opened.

filename can be a literal or a variable. You can specify the value in any of the following forms:
Special value *EXTDESC can be used to indicate that the parameter for the EXTDESC keyword should also be used for the EXTFILE keyword.
  1. You cannot specify *CURLIB as the library name.
  2. If you specify a file name without a library name, *LIBL is used.
  3. The name must be in the correct case. For example, if you specify EXTFILE(filename) and variable filename has the value 'qtemp/myfile', the file will not be found. Instead, it should have the value 'QTEMP/MYFILE'.
  4. This keyword is not used to find an externally-described file at compile time. Use the EXTDESC keyword to locate the file at compile-time.
  5. When EXTFILE(*EXTDESC) is specified, the EXTDESC keyword must also be specified for the file, or for the parent file if the file is defined with the LIKEFILE keyword.
  6. If a variable name is used, it must be set before the file is opened. For files that are opened automatically during the initialization part of the cycle, the variable must be set in one of the following ways:
    • Using the INZ keyword on the D specification
    • Passing the value in as an entry parameter
    • Using a program-global variable that is set by another module.
If you have specified an override for the file that RPG will open, that override will be in effect. In the following code, for the file named INPUT within the RPG program, the file that is opened at runtime depends on the value of the filename field.
 Finput     if   f   10        disk    extfile(filename)
If the filename field has the value MYLIB/MYFILE at runtime, RPG will open the file MYLIB/MYFILE. If the command OVRDBF MYFILE OTHERLIB/OTHERFILE has been used, the actual file opened will be OTHERLIB/OTHERFILE. Note that any overrides for the name INPUT will be ignored, since INPUT is only the name used within the RPG source member.
Figure 1. Examples of the EXTFILE keyword
 * The name of the file is known at compile time
Ffile1     IF   F   10        DISK    EXTFILE('MYLIB/FILE1')
Ffile2     IF   F   10        DISK    EXTFILE('FILE2')
 * The name of the file is in a variable which is
 * in the correct form when the program starts.
 * Variable "filename3" must have a value such as
 * 'MYLIB/MYFILE' or 'MYFILE' when the file is
 * opened during the initialization phase of the
 * RPG program.
Ffile3     IF   F   10        DISK    EXTFILE(filename3)

 * The library and file names are in two separate variables
 * The USROPN keyword must be used, so that the "filename4"
 * variable can be set correctly before the file is opened.
Ffile4     IF   F   10        DISK    EXTFILE(filename4)
F                                     USROPN
D filename4       S             21A                   
 * EXTFILE variable "filename4" is set to the concatenated
 * values of the "libnam" and "filnam" variables, to form
 * a value in the form "LIBRARY/FILE".
C                   EVAL      filename4 = %trim(libnam) + '/' + filnam
C                   OPEN      file4
 * At compile time, file MYLIB/MYFILE5 will be used to
 * get the external definition for the file "file5",
 * due to the EXTDESC keyword.
 * At runtime, the file MYLIB/MYFILE5 will be opened,
 * due to the EXTFILE(*EXTDESC) keyword.
Ffile5     if   e             DISK
F                             EXTFILE(*EXTDESC)
F                             EXTDESC('MYLIB/MYFILE5')