COBOL Manual for TNS/E Programs (H06.08+, J06.03+)
in any structured (sequential) file in ascending alternate-key order. You can also execute sequential
READ REVERSED statements to read records in reverse order.
The key-of-reference concept enables you to select one of several possible keys and then use a
single sequential READ statement to read a subset of records in a file.
Suppose that you have the personnel record in Example 285, and that the employee number
(which is not even part of the record) is the record number and therefore the prime key. By selecting
an alternate key as the key of reference, you can start reading at the first “Adams” in the file, the
first member of department 3141, or the first person having the job “Clerk.” Then you can use a
single READ statement to read successive records for employees named “Adams,” successive
records for employees whose names follow “Adams” alphabetically, records of employees in the
department number 3141 or higher, or records of employees whose job title is “Clerk” or follows
“Clerk” in collating sequence order.
Uppercase and lowercase letters are not equivalent in keys. When a data item with a mixed-case
value is to serve as a key, you have these choices:
• Leave the value alone, and accommodate any case differences.
• Shift the value into uppercase in the existing data item.
• Create an uppercase copy of the value in another data item in the record and use the uppercase
copy for key operations.
Alternate Record Keys
An alternate record key (or alternate key) is a data item, other than the prime record key, whose
value identifies a record in a structured file. COBOL restricts alternate keys to indexed files.
HP COBOL also allows alternate keys in entry-sequenced (sequential) and relative files.
In HP COBOL, an alternate key can occur anywhere in a record. The DUPLICATES phrase of the
ALTERNATE RECORD KEY clause of the file-control entry determines whether alternate key values
must be unique. If unique, an alternate key can have up to 253 characters; otherwise, it can have
up to 253 characters minus the length of the prime key. In H06.28/J06.17 RVUs with specific
SPRs and later RVUs, for Key Sequenced files, a unique alternate key can have up to 2046
characters; a non-unique alternate key can have up to 2046 characters minus the length of the
prime key. For other files, a unique alternate key can have up to 253 characters; a non-unique
alternate key can have up to 253 characters minus the length of the prime key. For a list of the
required H06.28/J06.17 SPRs, see “SPR Requirements for Increased Enscribe Limits for the
H06.28/J06.17 Release” (page 38). Alternate keys can overlap both each other and the prime
key, but no two alternate keys can start at the same character position (offset) in the record.
Enscribe implements alternate keys using one or more alternate-key files. For each file with one or
more alternate keys (primary file), Enscribe maintains at least one alternate-key file. For each unique
alternate key with a different key length, Enscribe maintains a separate alternate-key file. You can
refer to multiple unique alternate keys of the same key length through a single alternate-key file.
The directory entry for the primary file with alternate keys includes the names and other attributes
of the associated alternate-key files.
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.
870 Disk Input and Output










