How to open file in different modes in RPG?

23,730 pts.
Tags:
iSeries
RPG
RPG File Locks
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.
ASKED: April 21, 2009  11:20 AM
UPDATED: November 19, 2009  5:50 PM

Answer Wiki

Thanks. We'll let you know when a new response is added.

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.

Discuss This Question: 2  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • Cypherskull
    why do i need to rename the record format??
    25 pointsBadges:
    report
  • Teandy
    Because you can not have the same record format defined more than once in a program.
    5,860 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following