.st0{fill:#FFFFFF;}

over-riding IBM i files using OVRDBF and EXTFILE 

 January 26, 2010

By  NickLitten

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
RPG Code Snippet/free
 begsr *inzsr;
  VariableFileName = %char(%trim('some-value-passed-into-the-program-on-a-parm));
  monitor;
    open VariableFileName;
  on-error *file;
  endsr;
 /end-free

NickLitten


IBM i Software Developer, Digital Dad, AS400 Anarchist, RPG Modernizer, Shameless Trekkie, Belligerent Nerd, Englishman Abroad and Passionate Eater of Cheese and Biscuits. Nick Litten Dot Com is a mixture of blog posts that can be sometimes serious, frequently playful and probably down-right pointless all in the space of a day. Enjoy your stay, feel free to comment and remember: If at first you don't succeed then skydiving probably isn't a hobby you should look into.

Nick Litten

related posts:

{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}
__CONFIG_colors_palette__{"active_palette":0,"config":{"colors":{"cff50":{"name":"Main Accent","parent":-1},"a344d":{"name":"Accent Transparent","parent":"cff50"}},"gradients":[]},"palettes":[{"name":"Default","value":{"colors":{"cff50":{"val":"var(--tcb-skin-color-0)"},"a344d":{"val":"rgba(46, 138, 229, 0.85)","hsl_parent_dependency":{"h":210,"l":0.54,"s":0.78}}},"gradients":[]},"original":{"colors":{"cff50":{"val":"rgb(0, 178, 255)","hsl":{"h":198,"s":1,"l":0.5}},"a344d":{"val":"rgba(0, 178, 255, 0.85)","hsl_parent_dependency":{"h":198,"s":1,"l":0.5}}},"gradients":[]}}]}__CONFIG_colors_palette__

Get In Touch

Iā€™m always looking for awesome input, feedback and critique!

>