Using the OVRDBF command to change a member name or point an RPG IV database file at a file in another library has been practiced for years. But in Version 5 of OS/400, IBM added support to RPG IV that allows you to avoid specifying overrides for simple processes, such as opening a different member or pointer at a different library.
The file description keywords EXTFILE and EXTMBR were added in V5R1, and they allow you to specify the name of the file, library, and member to be opened at runtime. The file description still uses the hard-code file name in columns 7 to 16 of the File specification as the externally described file definition, and you still reference the file throughout the program using this name, but the EXTFILE keyword can contain the name of a field that contains the runtime file name, and the EXTMBR keyword can contain the name of a field that contains the runtime member name.
You may use either or both of these keywords. Neither is required. To use them, specify the field name within the parentheses of the keyword and make sure that field contains a valid name when the program is started. If it doesn't, the program will generate an error.
Here's a simple example that uses the EXTFILE keyword only.
D myFile S 21A Inz('QGPL/CUSTMAST')
EXTFILE(myFile) is specified, and then the variable named MYFILE is defined as a 21-position character field. It must be 21 bytes because the syntax of the file in the field is the same as the way it is specified on the OVRDBF command, which is library/object and includes the forward slash qualifier symbol.
Unlike OVRDBF, EXTFILE and EXTMBR open the file and/or members directly without applying an override. This is subtle but important because if you try to view the open files using option 15 from the WRKJOB menu, you will not see the file listed. You need to use option 14 instead.
Since the variable containing the file or member name must be populated when the program begins, it is often advantageous, although not required, to specify the USROPN keyword along with EXTFILE or EXTMBR and then open the file yourself in the Calculation specifications. For example:
D myFile S 21A
C eval myFile = 'QGPL/CUSTMAST'
C Open CustMast
At this point, the file is set to CUSTMAST in QGPL and is open. This could have easily been a file name passed in as a parameter, or retrieved from a data queue, or some other technique.
One last note: The EXTFILE and EXTMBR keywords allow you to specify literals. That is, they allow you to hard-code the file or member names you want to use. If this works for your situation, simply specify the values within quotes in all uppercase and things will work fine. For example, to open the last member in the CUSTMAST file, the following code could be used:
LATEST COMMENTS
MC Press Online