Open a file twice in RPG without using logicals?
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.
Re: Open a file twice in RPG without using logicals?
xyzzy wrote:[color=blue]
> 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.
>[/color]
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
Re: Open a file twice in RPG without using logicals?
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
xyzzy wrote:[color=blue]
> 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.[/color]
Re: Open a file twice in RPG without using logicals?
On Aug 17, 8:30 pm, CRPence <crpe...@vnet.ibm.com> wrote:[color=blue]
> 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 )[/color]
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.
Re: Open a file twice in RPG without using logicals?
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
xyzzy wrote:[color=blue]
> On Aug 17, 8:30 pm, CRPence <crpe...@vnet.ibm.com> wrote:[color=green]
>> 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 )[/color]
>
> 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.[/color]
Re: Open a file twice in RPG without using logicals?
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.
Re: Open a file twice in RPG without using logicals?
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
Re: Open a file twice in RPG without using logicals?
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)