23,625 pts.
 How to open file in different modes in RPG?
Hi, There have been a lot of changes in RPG over the last few years and I've lost track of many of these changes, so I have a question about file opens in RPG :- Is it possible to open a file for either input only or update without using overrides (and preferably without multiple F-specs)? The idea is to have one program for enquiry and maintenance using a parameter to select whether enquiry only or maintenance. If enquiry mode, then the file only needs to be opened for input, otherwise it will need to be opened for update as well. I'm trying to reduce the number of locks used on the data files. Any ideas? Thanks in advance. Regards, Martin Gilbert.

Software/Hardware used:
ASKED: April 21, 2009  11:20 AM
UPDATED: November 19, 2009  5:50 PM

Answer Wiki:
Martin Here is an idea -- this uses two F specs, The F specs use USROPN and cannnot name the same file But the one with the bogus name uses EXTFILE to redirect to the same file that the other names. Note: the file name in the 'D' spec must be caps Throughout the code you will need Open's, Setll, Read, Chain for both and just use the one indicated by the Mode. I usually move these snippets to a sub procedure or subroutine. When compiling you will need to a dup object filenameI like filename or ovrdbf filenameI to filename. Since the code will only open one of the paths - the locks you establish will be based on the mode. FfilenameI if e k DISK USROPN ExtFile(fileinput) F RENAME(FileRec : FileRecI) Ffilename Uf a e k DISK USROPN D fileinput S 21 inz('FILENAME') D mode S 1 inz(' ') C if mode=' ' C open filenamei C else C open filename C endif C close filenamei C eval *inlr = *on C return Phil ============ Hi Phil, Thanks! That's just the sort of thing I was looking for. I don't mind needing an OVRDBF to compile, I just don't want to use one at runtime. Perfect!. Cheers, Martin.
Last Wiki Answer Submitted:  April 21, 2009  2:14 pm  by  philpl1jb   44,630 pts.
All Answer Wiki Contributors:  philpl1jb   44,630 pts.
To see all answers submitted to the Answer Wiki: View Answer History.


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


 

why do i need to rename the record format??

 25 pts.

 

Because you can not have the same record format defined more than once in a program.

 5,860 pts.