HP RPG/XL Programmer's Guide (30318-90001)

3- 15
Reading a KSAM File Randomly and Sequentially Using Different Keys. This
section explains how to access a file both randomly and sequentially
using different key fields. There are two ways to do this. For both
methods you describe the files in the program as if they were two
separate entities. In the first method, enter two FILE commands (
file
equations
) before executing the program. This method is easier to use
and less likely to result in access conflicts than the second method. In
the second method, enter File Description Continuation lines for each
file, equating them to the same physical file. The second method treats
the two files as one in the program and is more memory-efficient. The
next two sections give examples of these two methods.
Using File Equations
To use this method of processing a file randomly and sequentially, enter
File Description and Calculation Specifications similar to those shown in
Figure 3-13. The file MASTERC is a KSAM file that is processed randomly
and MASTERC is a KSAM file that is processed sequentially within key
limits.
Before executing the program shown in Figure 3-13 two FILE commands see
the
MPE XL Reference Manual
for information on the FILE command) must be
entered.
:FILE MASTERC=MASTFL
:FILE MASTERD=MASTFL
The FILE commands equate both MASTERC and MASTERD to the KSAM file,
MASTFL. MASTERC and MASTERD each have their own operating system file
number and current record pointer and each is opened and processed
independently of the other.
Figure 3-13. Reading a KSAM File Randomly and Sequentially - Using File Equations
Comments
1 This line defines the KSAM file, MASTERC.
Column 16 is C to indicate that the file is processed in a
CHAINed fashion.
Column 28 is R to indicate that MASTERC is processed randomly.