Essential AS400 Questions

What's the difference between providing UsrOpn and automatically opening files? Which is more efficient. What we need to give UsrOpn, since the program itself opens it during an I / O operation. PLease explain me with an example.

+3


source to share


4 answers


As stated in the documentation for the USROPN keyword , the goal is to give the first opener control of the programmer's file (RPG).

For example:



  • Use ADDPFM to create a new file item 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 into the program.
+4


source


The difference is "time". Automatic opening occurs before the calculator starts working. UsrOpn opens when you execute an OPEN statement in a calculation specification at a point in time.



In no way more effective

, if you are not aware of the surrounding programming. Each of them is effective when you need their behavior. None of these are necessary, as alternative programming techniques can be used, for example, to set overrides before the RPG program is called so that UsrOpn can be omitted.

+4


source


Just remember that USROPN has no effect when the file gets closed . 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

+3


source


Besides what others have suggested ...

One consideration: Using USROPN means to ensure that the file you advertised is not automatically opened . The User-Open specification encoding is the only effective way to ensure that the file is never opened. AFaIK that persist regardless of vs Linear loop.
http://www.ibm.com/support/knowledgecenter/ssw_ibm_i_71/rzasd/sc09250895.htm%23wq136

Opening files implicitly ...

The declared file never needs to be opened unless that file will reference any I / O during certain processing code. Due to the lack of an implicit file open according to the USROPN specification, creating an open data path (ODP) for this .mbr file generates an optional OPEN statement for this declared file.

Inevitably opening the item (s) of the database file, i.e. creating an ODP is costly. Thus, creating an ODP is best avoided if \, when the program has a path to code for which there is no intention of doing I / O in that ODP. Again ... The USROPN spec allows OPEN to be deferred until OPEN is needed, or allows, perhaps, never to issue OPEN against this file. If a file that can never be specified for I / O does not have a USROPN specification, then that file will be implicitly opened, which means that an ODP is created even though it is never used; that is, the program would do the wasteful / costly operation to nothing, and then possibly also the cost of close activities for an implicit closure.
http://www-01.ibm.com/support/knowledgecenter/ssw_ibm_i_71/rzasd/sc09250896.htm%23wq137

Closing files implicitly ...

Tangential consideration: with the same control, it is possible to make OPEN efficient on demand instead of incurring the cost of the operation performed during the initialization phase; those. avoid activity loaded in front. In some programs, this ability to delay opening can be valuable.

+2


source







All Articles