ALTERNATE RECORD KEY clause
The ALTERNATE RECORD KEY clause (format 2) specifies a data item within the record that provides an alternative path to the data in an indexed file.
- data-name-3
- An ALTERNATE RECORD KEY data item.
data-name-3 must be described within a record description entry associated with the file. The key can have any of the following data categories:
- Alphanumeric
- Numeric
- Numeric-edited (with usage DISPLAY or NATIONAL)
- Alphanumeric-edited
- Alphabetic
- External floating-point (with usage DISPLAY or NATIONAL)
- Internal floating-point
- DBCS
- National
- National-edited
- UTF-8
Regardless of the category of the key data item, the key is treated as an alphanumeric item. The collation order of the key is determined by the item's binary value order when the key is used for locating a record or for setting the file position indicator associated with the file.
data-name-3 must not reference a group item that contains a variable-occurrence data item. data-name-3 can be qualified.
If the indexed file contains variable-length records, data-name-3 need not be contained within the minimum record size specified for the file. That is, data-name-3 can exceed the minimum record size, but this is not recommended.
If the indexed file contains variable-length records, data-name-3 need not be contained within the minimum record size specified for the file. That is, data-name-3 can exceed the minimum record size, but this is not recommended.
The data description of data-name-3 and its relative location within the record must be the same as those used when the file was defined. The number of alternate record keys for the file must also be the same as that used when the file was created.
The leftmost character position of data-name-3 must not be the same as the leftmost character position of the prime record key, or of another alternate record key.
If the DUPLICATES phrase is not specified, the values contained in the ALTERNATE RECORD KEY data item must be unique among records in the file.
If the DUPLICATES phrase is specified, the values contained in the ALTERNATE RECORD KEY data item can be duplicated within any records in the file. In sequential access, the records with duplicate keys are retrieved in the order in which they were placed in the file. In random access, only the first record written in a series of records with duplicate keys can be retrieved.
For files defined with the EXTERNAL clause, all file description entries in the run unit that are associated with the file must have data description entries for data-name-3 that specify the same relative location in the record and the same length. The file description entries must specify the same number of alternate record keys and the same DUPLICATES phrase.