COBOL Manual for TNS and TNS/R Programs
Disk Input and Output
HP COBOL Manual for TNS and TNS/R Programs—522555-006
28-22
Alternate Record Keys
After you have established the key of reference, you can execute sequential READ 
statements (READ NEXT statements) to read successive records according to that 
key: records in a relative file in ascending record-number order, records in an indexed 
file in ascending prime-key order, or records 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 28-10, 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. 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.










