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:



Business users want new applications now. Market and regulatory pressures require faster application updates and delivery into production. Your IBM i developers may be approaching retirement, and you see no sure way to fill their positions with experienced developers. In addition, you may be caught between maintaining your existing applications and the uncertainty of moving to something new.
IT managers hoping to find new IBM i talent are discovering that the pool of experienced RPG programmers and operators or administrators with intimate knowledge of the operating system and the applications that run on it is small. This begs the question: How will you manage the platform that supports such a big part of your business? This guide offers strategies and software suggestions to help you plan IT staffing and resources and smooth the transition after your AS/400 talent retires. Read on to learn:
LATEST COMMENTS
MC Press Online