Function
The ALTERNATE RECORD KEY clause defines a further, alternative key, in addition to the primary key, which can be used to access the records of an indexed file.
Format
ALTERNATE RECORD KEY IS data-name [WITH DUPLICATES]
Syntax rules
data-name must specify an alphanumeric or national data item in a record description entry, and this record description entry must be associated with the file name to which the ALTERNATE RECORD KEY clause is subordinate.
data-name may be any fixed-length field, with a length of 1 to 127 bytes, within the record. data-name may be qualified, but not subscripted or indexed.
data-name may not reference a group item which contains an element with an OCCURS clause with DEPENDING ON phrase.
If the file contains variable-length records, the alternate key must be contained within the first x character positions of the record, where x equals the minimum record size specified for the file (see section "RECORD clause"), i.e. the length of the alternate key must fit into the shortest possible record.
Several (up to 30) alternate record keys may be specified for one file.
data-name must not refer to a data item whose start address (the leftmost character position) is identical with the start address of the primary record key or of any other alternate record key. Apart from this restriction, the primary record key and any alternate record key(s) may overlap.
General rules
The data description of data-name and the relative position of the data item defined as a key must be the same as those specified when the file was created. The number of alternate record keys must match the number specified when the file was created.
WITH DUPLICATES specifies that the value of the related alternate record key may occur in more than one record. Records with identical key values are also called "duplicates". If WITH DUPLICATES is not specified, the value of the related alternate key must be unique, i.e. it may not occur more than once in the file.
If there are several record description entries in a file, data-name needs to be described in only one of these entries. The position of the key field in the record defined by data-name is used implicitly for all keys in the other record description entries.
If the ALTERNATE RECORD KEY clause(s) refers/refer to an external file, the same number of ALTERNATE RECORD KEY clauses must be specified in any program that uses this external file; the length and position of the key fields in the record and, where applicable, the DUPLICATES phrase, must also be defined so as to be consistent.