Venkatesh
Venkatesh

Reputation: 31

Basic questions on AS400

What is diference between giving UsrOpn and automatic opening of files ? Which is more effective.. What do we have to give UsrOpn since program itself opens it during I/O operation. PLease explain me with example..

Upvotes: 3

Views: 1444

Answers (4)

CRPence
CRPence

Reputation: 1259

Besides what others have offered...

One consideration: Using USROPN is the means to ensure the declared file is not automatically opened. Coding the User-Open specification is the only effective way to ensure that a file will never get opened. AFaIK that hold irrespective of Cycle vs Linear.
http://www.ibm.com/support/knowledgecenter/ssw_ibm_i_71/rzasd/sc09250895.htm%23wq136

Implicit Opening of Files ...

A declared file need never be opened if that file will not be referenced for any I/O during a specific code-path of processing. For lack of an implicit open of the file, per the USROPN specification, the creation of the Open Data Path (ODP) for that file.mbr pends an optional OPEN statement against that declared file.

Unnecessarily opening database file member(s), i.e. the creation of the ODP, is expensive. Thus ODP creations are best avoided if\when the program has a code path for which there is no intention to perform I/O on that ODP. Again... The USROPN specification allows delaying the OPEN until the OPEN is required, or allows for possibly not ever issuing an OPEN against that file. When a file that may never be referenced for I/O lacks the USROPN specification, then that file would be implicitly opened, meaning the ODP is created despite never being utilized; i.e. the program would have performed a wasteful\expensive operation for naught, and then possibly also the expense of the close activity for an implicit close.
http://www-01.ibm.com/support/knowledgecenter/ssw_ibm_i_71/rzasd/sc09250896.htm%23wq137

Implicit Closing of Files ...

A tangential consideration: By that same means of control, the opportunity exists to make the OPEN become effectively on-demand instead of incurring the expense of the operation taken at initialization phase; i.e. avoid the activity being front-loaded. In some programs, that capability to delay the open might have value.

Upvotes: 3

Barbara Morris
Barbara Morris

Reputation: 3664

Just remember that USROPN has no effect on when the file gets closed. The RPG rules for closing files are the same for all files. http://www-01.ibm.com/support/knowledgecenter/ssw_ibm_i_72/rzasd/impcls.htm

Upvotes: 3

user2338816
user2338816

Reputation: 2163

The difference is "timing". Automatic opens happen before calculation specs start running. UsrOpn opens happen when you execute an OPEN instruction in the calculation specs, at your timing.

Neither is more effective unless the surrounding programming is known. Each is effective when you need their behavior. Neither one is actually necessary since alternative methods of programming can be used, e.g., to set overrides before the RPG program is called so that UsrOpn can be left out.

Upvotes: 4

James Allman
James Allman

Reputation: 41158

As stated in the documentation for the USROPN keyword the purpose to give the programmer (RPG) control of the file's first open.

For example:

  • Use ADDPFM to create a new file member at run-time.
  • Use OVRDBF to select a specific file, member or change other file parameters at run-time.
  • Use OPNQRYF to sort, filter or otherwise manipulate the file before the records are read in to the program.

Upvotes: 4

Related Questions