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

3-: 14
file as a CHAINed file and as a demand file in the same program.
To read randomly and sequentially by the same key define the file as a
full procedural file in the File Description Specification. Figure 3-12
show how to read a KSAM file randomly and sequentially using the key
field, DEPT. A department number is entered by a user from the terminal.
The program randomly reads the KSAM file, MASTFL, to access that
department. Once the department record is read, the program reads
subsequent records sequentially until no more records for that department
are found.
.
Figure 3-12. Reading a KSAM File Randomly and Sequentially - Using Full
Procedural Files
Comments
1 This line defines the KSAM file, MASTFL.
Column 16 is F to indicate that the file is a full procedural
file.
Column 32 is I to specify that this is a KSAM file.
2 This line reads MASTFL randomly by the department number field,
DEPT.
Columns 28-32 are CHAIN to specify that chained random
processing be performed for MASTFL. This key is DEPT.
3 This line starts the code that processes MASTFL sequentially by
key.
Columns 28-32 are SETLL to set the beginning key value for
MASTFL. SETLL sets the file pointer to the key value placed in
DEPT.
4 This line starts the loop that reads the KSAM file sequentially
by key.
5 This line reads MASTFL until there are no more records having a
department equal to DEPT.