COBOL Manual for TNS and TNS/R Programs
Disk Input and Output
HP COBOL Manual for TNS and TNS/R Programs—522555-006
28-23
Positioning
Each record of an alternate-key file has three fields: the alternate key specifier, the
value of the alternate key, and the value of the prime key. An alternate key specifier is
a two-character code that identifies an alternate key defined for a primary file.
An alternate-key file is a key-sequenced file. For every record in the primary file, there
are at most as many records in the alternate-key file as there are alternate keys
declared for that alternate-key file.
Using FUP CREATE, you can specify a null-value character for each alternate key. Any
record with an alternate-key field composed entirely of the null-value character is not
represented in the alternate-key file. This strategy saves space when you have
alternate keys for which many records have the same value, such as zeros or spaces,
and you are not interested in locating these records by their alternate key.
If you have a structured file without alternate keys and you want it to have alternate
keys, you can use FUP to create the alternate-key file and to load the alternate-key file.
If you describe your database with DDL, the DDL compiler can produce the necessary
FUP commands to create prime-key and alternate-key files.
For more information about alternate keys, see the Guardian Programmer’s Guide.
Positioning
Enscribe provides three positioning modes: approximate, exact, and generic. Only
approximate positioning is available in COBOL; both approximate and generic
positioning are available in HP COBOL.
Neither COBOL nor HP COBOL supports exact positioning; it involves a variable-
length key. In using Enscribe directly, you specify a maximum key length for a key-
sequenced file’s prime key or for any alternate key. When you call the KEYPOSITION
routine (analogous to HP COBOL’s START statement), you can specify a length and a
value: a compare length that is shorter than or equal to the maximum key length, and a
value of that length for the key. Exact positioning means that the only records delivered
are those whose key is the same length as the compare length and whose value is the
same as the key value. If the key is unique, at most one such record exists in the file.
Caution. Because updating the alternate-key file can require multiple write operations, certain
types of failures can cause the operating environment to fail to record alternate keys. The
record and some of its alternate keys might be updated while other alternate keys might not be
updated. To prevent this, use TMF to verify that an update to a file with alternate keys is either
completed or aborted. For information about TMF, see Section 32, Fault-Tolerant Processes
.