OVRDBF – Override Database File
You can use the Override with Database file (OVRDBF) command to replace the database file named in a CL program or to change certain parameters of the existing database file. It can be overridden at a certain invocation level within the stack or set to be job wide.
Secondary over-rides can occur further down a program call stack and secured from existing over-rides using the SECURE(*YES) parm.
EXTFILE – External File
Now that I’ve said that – I much prefer the technique of handling file override within my RPG program code itself.
Lets try an example, if had an RPGLE program with a file called SOMEFILE needs to be overridden to file named NEWFILE it might be coded like this. Please remember that this does not need any kind of OVRDBF to be issued prior to the program running:
FSOMEFILE IF E K DISK EXTFILE(NEWFILE)
Furthermore, to read a specific member in that file you can simply add the EXTMBR parameter:
FSOMEFILE IF E K DISK EXTFILE(NEWFILE) EXTMBR(MBR01)
How about going further and telling the RPGLE what library to use for the file:
FSOMEFILE IF E K DISK EXTFILE(FATLIB/NEWFILE) EXTMBR(MBR01)
File names can also be a variable. Huzzah! As long as this is defined before the file is opened then this really spices things up:
FSOMEFILE IF E K DISK EXTFILE(FATLIB/VariableFileName) EXTMBR(MBR01) USROPN
/free begsr *inzsr; VariableFileName = %char(%trim('some-value-passed-into-the-program-on-a-parm)); monitor; open VariableFileName; on-error *file; endsr; /end-free