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

3- 7
Columns 24-27 specify the record length, 4. (XSORT always
creates ADDROUT records that are four bytes long.)
Columns 29-30 contain the key field length, 4.
Column 32 is T to specify that this is an ADDROUT file.
Column 39 is E to indicate that there is a File Extension
Specification for this file.
2 This line defines the KSAM file, MASTFL.
Column 28 is R to indicate that MASTFL is accessed randomly.
Column 31 is I to specify that records in MASTFL are accessed by
their record addresses.
3 This line specifies that RAFFILE contains the record addresses
for accessing records in MASTFL.
Reading a KSAM File Sequentially Within Key Limits. When you need to
process a set of records in a KSAM file that have continuous key values,
you can process that file sequentially within key limits. Reading within
key limits may be used to process a range of part numbers (15000-15999)
in an inventory file, for example.
To read sequentially within key limits, specify the key value for the
first record then read the KSAM file sequentially until all records with
that key have been processed.
The following lines list the KSAMUTIL commands that create the KSAM file
used in Figure 3-5, through Figure 3-8. The KSAM file, MASTFL, has two
keys. The primary key field (KEY=B,1,4) cannot have duplicates. The
secondary key field (KEY=B,25,15,,RDUP) can have duplicates.
:RUN KSAMUTIL.PUB.SYS
>BUILD MASTFL;REC=-256,4,F,ASCII;DISC=20000,20,4;KEYFILE=MASTFLK;&
>KEY=B,1,4;KEY=B,25,15,,RDUP
Supplying Full Key Values (Method 1)
Figure 3-5 shows how to read all records in a KSAM file having a specific
key value. The KSAM file, MASTFL, is read by its secondary key field,
LNAME (positions 25-39). In this example, a user enters a specific last
name from the terminal. The program reads all records in the file with
this last name. When there are no more records for the name, the program
prompts the user to enter another name.