20 pts.
 useropen
Hi, What is the purpose of USROPN keyword?

Software/Hardware used:
ASKED: August 12, 2008  10:06 AM
UPDATED: May 20, 2011  9:40 AM

Answer Wiki:
Hi, a programmer can explicitly open the files defined in the file specs with this key word specified in the RPGLE program. ------------------------------------------------------------------- This is usually done so that your program can determine things like a specific member to override to before opening the file. Then when you open the file you can process that member.
Last Wiki Answer Submitted:  August 12, 2008  1:54 pm  by  ten2008   1,150 pts.
All Answer Wiki Contributors:  ten2008   1,150 pts.
To see all answers submitted to the Answer Wiki: View Answer History.


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


 

USROPN is only required if you need to control the initial opening of a file.
Your program can close any open file and re-open it as needed without specifying USROPN. Notice the sequence . . . “close and re-open”.
If you specify USROPN, you must add code to your program to open the file.

 5,525 pts.

 

Woodengineer, I don’t think you are correct.

RPG will ‘initially’ open a file if USROPN is NOT specified. That file will stay open until the program ends with *INLR set *ON, or until that program is closed using FREE from a calling program, or until RCLRSC is used.

Without USROPN, there is no way an RPG program can close the file and then re-open it.

With USROPN, the RPG program will not open the file until an OPEN operation is executed for that file. You can then use CLOSE to close the file. You can do this as often as you want in the program.

Regards,

Sloopy

 2,195 pts.

 

Not true Sloopy.

I do that all the time for a system configuration file that is only read once during initialization.

I let the program open the file (no USROPN), READ file, CLOSE file.

If I wanted to I could re-OPEN file.

USROPN only controls the initial automatic opening of the file

Kevin Ketzler – Affiliated

 7,185 pts.

 

I agree with Kevin, you can CLOSE a file opened by the cycle although I haven’t tried to re-open one. I’ll go with experience that you can, then.

I would think that, for some clarity, why not then just add the USROPN and the first OPEN. There are those out there that have no experience with MR, Lx’s, detail and total-time output and other cycle-related favorites of the older generation who actually have to see the code to understand what’s going on. Those were the days…

 90 pts.

 

Sloopy,

I stand by my answer. I’ve used the technique in my my programs.

The following is copied directly from IBM’s ILE RPG Reference manual for V5R3, page 285:

“The USROPN keyword is required for programmer control of only the first file opening. For example, if a file is opened and later closed by the CLOSE operation, the programmer can reopen the file (using the OPEN operation) without having specified the USROPN keyword on the file description specification. See also “EXTIND(*INUx)” on page 277.”

 5,525 pts.

 

Hi,

This seems to be something that has been quietly added to RPG at some point. I’m 100% sure that in older versions of RPG/400 if you didn’t have the UC on your file spec and tried to OPEN or CLOSE a file, your program wouldn’t even compile.

I’ve tried this as a test and a program will compile with OPEN and CLOSE and no USROPN for a file, but will not compile if you specify USROPN without an OPEN or CLOSE.

Before you ask – yes, I was bored.

Regards,

Martin Gilbert.

 23,625 pts.

 

I stand corrected.

Well, I lounge around corrected, anyway.

As Martin says, this does appear to be something that crept in to RPG in the move between RPGIII and RPGIV – UC behaves as I described, and USROPN behaves as Woody describes.

I just don’t remember any notification of the change of function, but then, it was a long time ago now and there was so much to read!

Regards,

Sloopy

 2,195 pts.

 

Hi,

UC now also works this way, it’s not just for USROPN. I don’t remember seeing this announced either.

Regards,

Martin.

 23,625 pts.