HP RPG/XL Programmer's Guide (30318-90001)
3-: 12
Figure 3-9. Reading a KSAM File Randomly by Key
Comments
1 This line defines the KSAM file, MASTFL.
Column 16 contains C to indicate that the KSAM file is accessed
in chained fashion.
Column 28 is R to specify random processing.
Columns 29-30 contain 4 to specify the key length.
Column 31 contains A to specify that the key is alphanumeric.
Column 32 contains I to specify that this is a KSAM file.
2 This line reads MASTFL by primary key.
Columns 18-21 contain the name of the key field, DEPT.
Columns 28-32 contain the word CHAIN to read the file in a
chained fashion during the calculation portion of the logic
cycle.
Columns 54-55 contain the resulting indicator (60) that is
turned on when no record can be found for the value in DEPT.
Specifying the Keys Using a RAF
If you need to process KSAM records randomly by key and you know (before
running a program) what the key values are, use a RAF to hold them. RPG
will then use the key values in the RAF to access records in the KSAM
file. RAFs let you change key values without modifying and recompiling
the RPG program.
You can create a RAF using any standard text editor, for example EDITOR.
Enter key values starting with position one. You can enter more than one
key on each line, if you wish, but there must be no intervening spaces.
(See the
HP RPG Reference Manual
for details on creating a RAF.)
Figure 3-10 and Figure 3-11 show how to read a KSAM file randomly using a
RAF. Figure 3-10 lists the key values in the RAF and Figure 3-11 gives
the RPG program that processes the RAF. The keys in the RAF are four
digits long. They are: 0006, 0010, 0028, 0012, 0013, 0016, 0020, 0036,
0040, 0026, 0011, 0029, 0030 and 0080.