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

3- 3
Manual
.)
For example, the following command copies 50 records (records 0 through
49) from the KSAM file, TRANSFL, to the KSAM file, MASTFL. MASTFL is a
new file and is created along with its key file, MASTFLK.
FCOPY FROM=TRANSFL;TO=(MASTFL,MASTFLK);SUBSET=0,49
If MASTFL and its key file already exist, the following command can be
used to copy the first 50 records in TRANSFL to it.
FCOPY FROM=TRANSFL;TO=MASTFL;SUBSET=0,49
NOTE You can create an empty KSAM file by specifying SUBSET=0,0 in the
FCOPY command. To copy all records to the new file (to duplicate
it), omit the SUBSET=option.
Creating a KSAM File Within an RPG Program. You can use an RPG program
to create and load data into a single-key KSAM file. You define the KSAM
file as an output file and include KSAM entries in the File Description
and File Description Continuation Specifications. If the KSAM file does
not already exist, RPG creates it using these specifications.
Figure 3-1 shows part of the transaction file used by the program in
Figure 3-2 to create a KSAM file. The transaction file, TRANSFL,
contains customer charge information that is used to create a master KSAM
transaction file, MASTFL. The first field of each record in the
transaction file is the customer's identification number and it is the
key field for MASTFL. For example, the first customer identification
number is 00216. (Records do not have to be sorted by customer
identification number before running the RPG program; KSAM automatically
orders the records.) Following the customer number in each transaction
record is the charge amount field. For example, 00342 ($3.42) is the
charge amount for customer 00216.
_____________________________________
| |
| 0021600342 |
| 0365416514 |
| 0720001517 |
| 0021601802 |
| 0321004532 |
| 0045318455 |
| 8206603324 |
| 5122101088 |
| 0321006702 |
| . |
| . |
| . |
| |
| |
_____________________________________
Figure 3-1. Creating a KSAM File Within an RPG Program - A Sample Input File
TRANSFL
The KSAM file in Figure 3-2 can contain up to 1023 records (this is the
default). If your KSAM file is larger, enter a FILE command before
running the program (for information on the FILE command, see the
MPE XL
Commands Reference Manual
). For example, this FILE command specifies a
MASTFL size of 10,000 records:
:FILE MASTFL;DISC=10000