The KEY specifier defines the access keys for records in an indexed file. It takes the following form:
The defaults are CHARACTER and ASCENDING.
The key starts at position e1 in a record and has a length of e2-e1+1 . The values of e1 and e2 must cause the following calculations to be 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 is the primary key (the default key). It usually has a unique value for each record.
You can also define alternate keys. RMS allows up to 254 alternate keys.
If a file requires more keys than the OPEN statement limit, you must create the file using another language or the File Definition Language (FDL).
Specifying and Referencing Keys
You must use the KEY specifier 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.
However, if you use the KEY specifier 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 More Information:
For details on the FDL, see the OpenVMS Record Management Services Reference Manual.