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

3-: 22
1 This line defines the KSAM file, MASTFL.
Column 16 is U to indicate that the KSAM file will be updated.
Column 17 is C for CHAINed (random) access.
Column 66 is A to indicate that records will be added to the
file.
2 This line reads MASTFL randomly.
Columns 18-27 contain DEPT to specify the primary key field for
MASTFL.
Columns 28-32 contain CHAIN to read a record randomly.
Columns 54-55 contain 80 to turn on indicator 80 when a record
is not found in MASTFL.
3 This line directs RPG to perform exception output when a
department record is not found (indicator 80 is turned on).
Columns 10-11 contain 80 to specify that this line be executed
when indicator 80 (line 2) is turned on.
Columns 28-32 contain EXCPT to direct RPG to write records while
calculations are in progress.
Columns 43-48 are ADDREC, the EXCPT Name for the record to be
added.
4 This line defines the MASTFL file output record for new (added)
records.
Column 15 is E to identify this record as an exception output
record.
Columns 16-18 are ADD to specify that records be added to the
KSAM file.
Columns 32-37 are ADDREC to specify the EXCPT Name for the
record to be added.
Deleting Records from a KSAM Disc File
This section tells you how to delete records from a KSAM file.
When you delete a record, you mark it as inactive. KSAM automatically
enters a -1 (hexadecimal FFFF) in the first two bytes of the record.
Deleted records remain in the file but are ignored when you read it.
When using KSAM files, it is a good idea to start the data fields of each
record in position three. This enables you to recover inactive records
in their entirety, if this becomes necessary. There are two ways to
access records that have been marked as deleted. You can use an RPG
program to read the file chronologically or you can use FCOPY. When using
FCOPY, copy the KSAM file with the NOKSAM file option.
To physically remove inactive records from a KSAM file, use FCOPY (with
the KSAM default option). FCOPY copies the file,except for inactive
records to either an MPE file or another KSAM file. You can also use an
RPG program to remove inactive records by copying the KSAM file to
another file.