COBOL Manual for TNS and TNS/R Programs

Disk Input and Output
HP COBOL Manual for TNS and TNS/R Programs522555-006
28-36
Files With Alternate Keys
Declaring Null Values for Alternate Keys
When you create an alternate-key file with FUP CREATE, you can declare a null value
for any alternate key. When you insert a record, if each byte in the alternate-key field
contains that null value, the alternate-key reference is not added to the alternate-key
file. This reduces both the size of the alternate-key file and the access time for the
records of a file being accessed according to that alternate key. It also makes the
records that have null values invisible when you read the file by an alternate key for
which a null value has been defined.
If you update a record in the file in such a way that the alternate-key field receives a
null value, the alternate-key reference for that record is deleted from the alternate-key
file.
If you read a file according to an alternate key for which a null value has been defined,
records containing the null value of the alternate key are not read.
The most common null values are the ASCII space and the binary zero.
Making the Main File Entry-Sequenced or Relative
If your main file has several keys defined but no one key is used substantially more
than any other keys, consider making that main file a relative or entry-sequenced file
rather than a key-sequenced file.
Every time you read a key-sequenced file by prime key, you cause two possible
physical read operations: one for the key and one for the record. Every time you read a
key-sequenced file by alternate key, you cause four possible physical read operations:
one for the alternate key, one for the alternate-key record, one for the prime key, and
one for the record. If the main file has two keys and the probability of reading the file by
any given key is about even, then half the time you could cause two physical read
operations and half the time you could cause four. For each logical read operation, you
average three physical read operations.
If the main file has two keys and the probability of reading the file by any given key is
about even, you also average three physical read operations for each logical read
operation if you choose entry-sequenced or relative organization for the main file;
however, if the main file has more than two keys, the average number of physical read
operations per logical read operation improves.
The average number of physical read operations per logical read operation improves
even further when several records in the alternate-key file or main file are in the same
physical block and no physical read is required, such as when you are reading
sequentially on an alternate key.