10 pts.
 ovrdbf in rpg
hi guys.. i am getting a file name as a variable from CL program. based on some condition i want to write in differnt members of the file.since the file name is stored in a variable i cant able to declare it in f spec. so i created a duplicate object for that file and i declare it in f spec. Now i want to override that file to the filename stored in the variable and to different members... any clues Guys... If possible provide some examples it ll be useful. since the filename is stored in a variable i dont know how to override.

Software/Hardware used:
as400-RPG
ASKED: November 29, 2009  6:04 AM
UPDATED: November 30, 2009  8:16 PM

Answer Wiki:
Use the USROPN keyword in the F spec for the file. Then just prior to doing an OPEN in the calc spec, call QCMDEXEC to do an OVRDBF to the file and/or member you want to use. * Here is an example: // override to new member. cmdString ='OVRDBF FILE(ADDLNAMMBR) TOFILE(' + %trim(&fileName)'); callp cmd(cmdString:300); // open the file. open ADDLNAMMBR; ========================================================== It depends on what version/release you're running and whether you're programming in ILE RPG or RPG/400. Recent ILE RPG allows you to use variables for both file name and member name. The file will be a USROPN file. Assign values to the variables and open the file. Here's some code using a variable for a fully-qualified file name and a constant for member name:<pre> FQCUSTCDT1 if e disk extfile( 'QIWS/QCUSTCDT' ) FQCUSTCDT2 if e disk usropn f extfile( CUSTCDT2 ) f extmbr( CDMBR ) f format( CUSREC : CUSREC2 ) f prefix( QC : 2 ) D CUSTCDT2 s 21 D CDMBR c 'MYMBR' CUSTCDT2 = %trimr( PgmLib ) + '/' + 'QCUSTCDT' ;</pre>Note that when compiled, the compiler needs to find file descriptions for both "QCUSTCDT1" and "QCUSTCDT2". Those can simply be temporary file objects that are deleted once the compile is finished. There are no overrides for this kind of coding. The RPG does it all. RPG/400 does not allow this technique, so it still requires OVRDBF. Tom
Last Wiki Answer Submitted:  November 30, 2009  8:16 pm  by  CharlieBrowne   32,915 pts.
All Answer Wiki Contributors:  CharlieBrowne   32,915 pts.
To see all answers submitted to the Answer Wiki: View Answer History.


Discuss This Question:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _