Discussion:
Open a file twice in RPG without using logicals?
(too old to reply)
xyzzy
2007-08-17 19:01:28 UTC
Permalink
Hi,

Is it possible in RPG to open a physical file twice, without resorting
to opening a logical file as well?

The situation is this:

An RPGLE program creates (via CRTDUPOBJ), opens and populates a
temporary keyed physical file in QTEMP. It then reads back through
this file validating each record. However, when certain record types
are found, the same file has to be checked for the existence of
dependent records, hence the need to open the file twice.

If I have to, I'll create a logical file in QTEMP (with the same keys
as the physical file) and use that, but I was hoping that I could just
open the physical file twice.

Thanks in advance for any suggestions.
Karl Hanson
2007-08-17 19:19:03 UTC
Permalink
Post by xyzzy
Hi,
Is it possible in RPG to open a physical file twice, without resorting
to opening a logical file as well?
An RPGLE program creates (via CRTDUPOBJ), opens and populates a
temporary keyed physical file in QTEMP. It then reads back through
this file validating each record. However, when certain record types
are found, the same file has to be checked for the existence of
dependent records, hence the need to open the file twice.
If I have to, I'll create a logical file in QTEMP (with the same keys
as the physical file) and use that, but I was hoping that I could just
open the physical file twice.
My experience with RPG is very limited, but I believe you could use the
OVRDBF (Override with Database File) CL command. If you have file
QTEMP/AA, declare two files in the program: AA and BB. Then before
running the program (and opening the files), do OVRDBF FILE(BB) TOFILE(AA).

--
Karl Hanson
CRPence
2007-08-17 19:30:36 UTC
Permalink
The option exists [beyond what may be in the language itself] to
define the file twice using the data management. Issue two overrides,
and open by each of the two names defined by the overrides. Thus if
files TEMPINP and TEMPUPD are declared in the program [for file
QTEMP/TEMPFILE that will exist at run-time], before running the program,
issue the following override requests:
OVRDBF TEMPINP QTEMP/TEMPFILE OVRSCOPE( as_required )
OVRDBF TEMPUPD QTEMP/TEMPFILE OVRSCOPE( as_required )
A separate logical file would generally be required only if the key
were different or some specific data [type] mapping were desirable; for
the key, perhaps just descend versus ascend. As well, SHARE(*YES) on
the override and having opened the file using OPNQRYF to establish an
alternate key allows a second view of the file without a logical file.
Then ensure the code does not attempt to access the same row for
update in both of the ODP [Open Data Paths]. If the read on the first
ODP doing the lookup is for update, then that read must release the lock
before the read for update on the second ODP if it must get past that
same row.

Regards, Chuck
--
All comments provided "as is" with no warranties of any kind
whatsoever and may not represent positions, strategies, nor views of my
employer
Post by xyzzy
Is it possible in RPG to open a physical file twice, without resorting
to opening a logical file as well?
An RPGLE program creates (via CRTDUPOBJ), opens and populates a
temporary keyed physical file in QTEMP. It then reads back through
this file validating each record. However, when certain record types
are found, the same file has to be checked for the existence of
dependent records, hence the need to open the file twice.
If I have to, I'll create a logical file in QTEMP (with the same keys
as the physical file) and use that, but I was hoping that I could just
open the physical file twice.
Thanks in advance for any suggestions.
xyzzy
2007-08-17 21:33:44 UTC
Permalink
Post by CRPence
The option exists [beyond what may be in the language itself] to
define the file twice using the data management. Issue two overrides,
and open by each of the two names defined by the overrides. Thus if
files TEMPINP and TEMPUPD are declared in the program [for file
QTEMP/TEMPFILE that will exist at run-time], before running the program,
OVRDBF TEMPINP QTEMP/TEMPFILE OVRSCOPE( as_required )
OVRDBF TEMPUPD QTEMP/TEMPFILE OVRSCOPE( as_required )
Thanks for the quick response.

Wouldn't the files TEMPINP and TEMPUPD both have to exist for to
program to compile? I'm not in front of an iSeries at the moment so
cannot try it.

Thanks again.
CRPence
2007-08-17 22:23:59 UTC
Permalink
If a compile(r) wants the file available for its declaration, beyond
a requirement for the file to exist just at run-time, then perform the
overrides for [during] the compile request, as well as at run-time.
Since the overrides are available only within the job [active to the
defined scope within that job], then a batch compile requires that the
overrides are established in the batch job before the compile request
starts.
If the ability to define the overrides as pre-compile action in a
batch compile is not available in the development tooling, then a CLP, a
CL batch stream, a REXX, or ¿other?, can be used to script/package the
override requests and the compile request to run in a submitted job.

Regards, Chuck
--
All comments provided "as is" with no warranties of any kind
whatsoever and may not represent positions, strategies, nor views of my
employer
Post by xyzzy
Post by CRPence
The option exists [beyond what may be in the language itself] to
define the file twice using the data management. Issue two overrides,
and open by each of the two names defined by the overrides. Thus if
files TEMPINP and TEMPUPD are declared in the program [for file
QTEMP/TEMPFILE that will exist at run-time], before running the program,
OVRDBF TEMPINP QTEMP/TEMPFILE OVRSCOPE( as_required )
OVRDBF TEMPUPD QTEMP/TEMPFILE OVRSCOPE( as_required )
Thanks for the quick response.
Wouldn't the files TEMPINP and TEMPUPD both have to exist for to
program to compile? I'm not in front of an iSeries at the moment so
cannot try it.
Thanks again.
Graybeard
2007-08-18 02:48:51 UTC
Permalink
Another way to handle files that don't exist -- We have a seperate
library where we have an empty file like the one to be created. This
library is added to the library list as the *last library just before
compile.
H***@sss-software.de
2007-08-18 08:06:22 UTC
Permalink
Hi,

yes, it is possible to access the same physical file twice in the same
program. But instead of using the CL-Command OVRDBF where you have to
take care of the override scope, I'd suggest to use the keyword
EXTFILE (and perhaps EXTMBR) in the F-Specs. It is also necessary to
rename the format name for at least one of the 2 files.

The files specified left hand in the F-Specs must exist at compile
time, because the RPG compiler integrates the file and field
description into the program object.

Before compiling just create a duplicate object (CRTDUPOBJ) of the
physical file without data, but with the expected names. After create
your program (and delete the temporary files).

Birgitta
xyzzy
2007-08-18 10:58:21 UTC
Permalink
Hi Birgitta,

Using EXTFILE was how I originally tried to solve this, but I hadn't
created a duplicate of the main work file and the compiler expected to
find the file on the f-spec. I'll give this approach another go.

Thanks for your help (and everyone else's suggestions)

Continue reading on narkive:
Loading...