Compaq AAQ2G1FTK Marine Radio User Manual


 
Processing Files and Records
6.1 Dening Files and Records
Indexed file organization allows you to use a key to uniquely identify a record
within the file. The location and length of the key are identical in all records.
When creating an indexed file, you must select the data items to be the keys.
Selecting such a data item indicates to the I/O system that the contents (key
value) of that data item in any record written to the file can be used by the
program to identify that record for subsequent retrieval. For more information,
see the Environment Division clauses RECORD KEY IS and ALTERNATE
RECORD KEY IS in the Compaq COBOL Reference Manual.
You must define at least one main key, called the primary key, for an indexed
file. You may also optionally define from 1 to 254 additional keys called alternate
keys. Each alternate key represents an additional data item in each record of the
file. You can also use the key value in any of these alternate keys as a means of
identifying the record for retrieval.
You define primary and alternate key values in the Record Description entry.
Primary and alternate key values need not be unique if you specify the WITH
DUPLICATES phrase in the file description entry (FD). When duplicate key
values are present, you can retrieve the first record written in the logical sort
order of the records with the same key value and any subsequent records using
the READ NEXT phrase. The logical sort order controls the order of sequential
processing of the record. (For more information about retrieving records with
duplicate key values, see the information about the READ statement in the
Compaq COBOL Reference Manual.)
When you open a file, you must specify the same number and type of keys that
were specified when the file was created. (This situation is subject to modification
by the check duplicate keys and relax key checking options, as well as a duplicate
key specification on an FD.) If the number or type of keys does not match, the
system will issue a run-time diagnostic when you try to open the file.
As your program writes records into an indexed file, the I/O system locates the
values contained in the primary and alternate keys. The I/O system builds these
values into a tree-structured table or index, which consists of a series of entries.
Each entry contains a key value copied from a record. With each key value is a
pointer to the location in the file of the record from which the value was copied.
Figure 6–5 shows the general structure of an indexed file defined with a primary
key only.
Processing Files and Records 67