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

3-: 6
Column 31 contains A to specify that the key field is
alphanumeric.
Column 32 contains I to specify that this is a KSAM file.
Columns 35-38 contain 1 to specify the starting location of the
key field.
Reading a KSAM File Sequentially by a Non-Key Field
This section explains how to read an entire KSAM file sequentially by a
non-key field. You can use any field that was not defined as a key when
the file was created. (This method of reading KSAM files also applies to
MPE files.)
To read a KSAM file sequentially by a non-key field, you must first
create a Record Address File (RAF). The RAF contains addresses of the
data records in the KSAM file in sorted order. You can use either
SORT/3000 or XSORT to create a RAF. XSORT is an RPG utility that is
documented in the
RPG Utilities Reference Manual
. SORT/3000 is a
general-purpose sort described in the
SORT-MERGE/XL Programmer's Guide
.
Once you create a RAF, you can use it in an RPG program to retrieve the
KSAM records in sorted order.
The following lines show how to enter XSORT parameters to order an
employee file, MASTFL, by employee zip code. (When MASTFL was created,
zip code was not specified as a key field.) The zip code field occupies
positions 60 through 64 in the KSAM records. The H Specification of
XSORT directs XSORT to create an Address Output (
ADDROUT
) file. ADDROUT
files are a special type of RAF containing sorted record addresses.
:FILE XSORTIN=MASTFL
:FILE XSORTOUT=RAFFILE;SAVE
:RUN XSORT.PUB.SYS
HSORTA 5A
FNC 60 64
:EOD
To process the ADDROUT file created by XSORT above, enter File
Description and File Extension Specifications as shown in Figure 3-4.
.
Figure 3-4. Reading a KSAM File Sequentially by a Non-Key Field
Comments
1 This line defines the RAF, RAFFILE.
Column 16 contains an R to indicate that RAFFILE contains record
addresses.
Column 17 is E to specify that reading continue to the end of
the file.