The KEY keyword defines the access keys for records in an indexed file. It takes the following form:
KEY = (kspec [,kspec] . . . )
e1:e2 [:dt[:dr]]
CHARACTER and ASCENDING are the default values.
The key starts at position e1 in a record and has a length of e2 - e1 + 1. The values of e1 and e2 must be such that the following calculations are true:
1 .LE. (e1) .AND. (e1) .LE. (e2) .AND. (e2) .LE. record-length 1 .LE. (e2-e1+1) .AND. (e2-e1+1) .LE. 255
If the key type is INTEGER, the key length must be either 2 or 4.
Defining Primary and Alternate Keys
You must define at least one key in an indexed file. This primary key is the default key. It usually has a unique value for each record.
You can choose to define alternate keys. RMS allows up to 254 alternate keys. However, individual OPEN statements only allow up to 84 key definitions, a number that is further reduced when additional keywords appear in the OPEN statement.
If a file requires more keys than the OPEN statement limit, you must create it from another language or with the File Definition Language (FDL).
Specifying and Referencing Keys
You must specify the KEY keyword when creating an indexed file. However, you do not have to respecify it when opening an existing file because key attributes are permanent aspects of the file. These attributes include key definitions and reference numbers for subsequent I/O operations. If you do choose to specify the KEY keyword for an existing file, your specification must be identical to the established key attributes.
Subsequent I/O operations use a reference number, called the key-of-reference number, to identify a particular key. You do not specify this number; it is determined by the key's position in the specification list: the primary key is key-of-reference number 0; the first alternate key is key-of-reference number 1, and so forth.
For details on the FDL, see the OpenVMS Record Management Services Reference Manual.