Introduction | Language Structure | IB Statements | File System | Comet 32 Runtime | Index |
| Parameter: | KEY=key-index |
| Discussion: | Used in input/output statements to specify the key index or
record number being accessed (read or written). If the key-index
is a string, it refers to an alphanumeric key in a keyed file. If
the key-index is a number, it refers to the record number in a
keyed or indexed sequential file.
For keyed files, the key-index can be any valid string expression. If the key-index is shorter than the file key size, it is padded with trailing blanks. If it is longer than the key size, excess trailing characters are truncated before the key search begins. If the key-index is not found in the key list, the record pointer is positioned at the next key and the exception path is executed. This is useful for finding a particular record for which you may know only the beginning part of the key. For indexed sequential files, the key-index can be any numeric expression (truncated to an integer value before the READ is attempted). A negative or zero index, or an index beyond the last record in the file, results in an exception branch. For more information, see Exception Handling. |
| Example: |
INPUT (0) CUSTNUM$ ! ENTER CUST. NO.
READ (1,1000) KEY=CUSTNUM$, EXCP=LABEL2 ! READ RECORD
.
LABEL2: IF EXCP = 32 THEN ... ! KEY NOT FOUND EXCEPTION
IF EXCP = 33 THEN ... ! RECORD LOCKED EXCEPTION
|