The key = clause

The key = clause

Non-sequential search commands (such as find[u] and read[u]), and the insert command, all require that key field values for the record are assigned, if the command is to work correctly. The search commands need to know what key data to look for, while the insert command needs to know the key values for the new record, firstly to check that the key is unique, and secondly to store the record in the file.

The default method of specifying the key is by direct assignment to the key fields. The command looks at the current value of each key field and assumes that these are the values required:

keyfield1 = expression
keyfield2 = expression
…
find record_id nsr = label riu = label

The key = clause enables the programmer to override the data currently in the file’s key fields by specifying a list of fields to be used in their place. The key = clause has the syntax:

key = expression [, expression]

The first value listed is assigned to the first key field of the record, the second to the second key field and so on. Standard rules of assignment are used. If the number of values listed is fewer than the number of file key fields, the extra keys are set blank. If the number of values listed is greater than the number of file key fields, the extra fields are discarded. Each key value may be a field, constant or expression.

The commands and declarations which may take a key = clause are:

find[u]

insert

read[u]

readkey

testkey


A key = clause must be provided for the following report declarations and commands:

!xfile

endrec

startrec


RELATED TOPICS

Keyed files

Reports