10.2.1.5 Key-Field-Value Specifier (VMS only)

The key-field-value specifier identifies the key field of a record that you want to access in an indexed file. The key-field value is equal to the contents of a key field. The key field can be used to access records in indexed files because it determines their location.

A key field has attributes, such as the number, direction, length, byte offset, and type of the field. The attributes of the key field are specified at file creation. Records in an indexed file have the same attributes for their key fields.

A key-field-value specifier takes the following form:

KEY[con]=val

con
Is a selection condition keyword specifying how to compare val with key-field values. The keyword can be any of the following:


In Ascending-Key Files: 
Keyword  Meaning 
EQ  The key-field value must be equal to val. KEYEQ is the same as specifying KEY without the optional con. 
GE  The key-field value must be greater than or equal to val. 
GT  The key-field value must be greater than val. 
NXT  The key-field value must be the next value of the key equal to or greater than val. 
NXTNE  The key-field value must be the next value of the key strictly greater than val. 
 
In Descending-Key Files: 
Keyword  Meaning 
EQ  The key-field value must be equal to val. KEYEQ is the same as specifying KEY without the optional con. 
LE  The key-field value must be less than or equal to val. 
LT  The key-field value must be less than val. 
NXT  The key-field value must be the next value of the key equal to or less than val. 
NXTNE  The key-field value must be the next value of the key that is strictly less than val. 

val
Is an integer or character expression. The expression must match the type of key defined for the file. For an integer key, you must pass an integer expression; it cannot contain real or complex data. For a character key, you can pass either a CHARACTER expression or a BYTE array that contains CHARACTER data.

The specifiers KEY, KEYEQ, KEYNXT, and KEYNXTNE are interchangeable between ascending-key files and descending-key files. However, KEYNXT and KEYNXTNE are interpreted differently depending on the direction of the keys in the file, as follows:

  In Ascending-Key Files  In Descending-Key Files 
Specifier:  Is Equivalent to Specifier: 
KEYNXT  KEYGE  KEYLE 
KEYNXTNE  KEYGT  KEYLT 

The specifiers KEYGE and KEYGT can only be used with ascending-key files, while the specifiers KEYLE and KEYLT can only be used with descending-key files. Any other use of these key specifiers causes a run-time error to occur.

When a program must be able to use either ascending-key or descending-key files, you should use KEYNXT and KEYNXTNE.

The Selection Process

To select key-field integer values, the process compares values using the signed integers themselves.

To select key-field character values, the process compares values by using the ASCII collating sequence.1 The comparative length of val and a key-field value, as well as any specified selection condition, determine the kind of selection that occurs. The selection can be exact, generic, or approximate-generic, as follows:

If val is longer than the key-field value, no selection is made and a run-time error occurs.

1 Other collating sequences are available. For more information, see the Guide to OpenVMS File Applications.


Previous Page Next Page Table of Contents