The START statement provides a means of positioning within an indexed or relative file for subsequent sequential record retrieval.
When the START statement is executed, the associated indexed or relative file must be open in either INPUT or I-O mode.
When the KEY phrase is specified, the file position indicator is positioned at the logical record in the file whose key field satisfies the comparison.
When the KEY phrase is not specified, KEY IS EQUAL (to the prime record key) is implied.
If you specify the KEY to be 'less than' or 'less than or equal to' the data item, the file position indicator is positioned to the last logical record that currently exists in the file that satisfies the comparison.
For an indexed file, if the key that satisfies the comparison has duplicate entries, the file position indicator is positioned to the last of these entries.
When the START statement is executed, a comparison is made between the current value in the key data-name and the corresponding key field in the file's index.
If the FILE STATUS clause is specified in the file-control entry, the associated file status key is updated when the START statement is executed (See File status key).
If the comparison is not satisfied by any record in the file, an invalid key condition exists; the position of the file position indicator is undefined, and (if specified) the INVALID KEY imperative-statement is executed. (See INTO and FROM phrases under “Common processing facilities”.)
Both the INVALID KEY phrase and an applicable EXCEPTION/ERROR procedure can be omitted.
This explicit scope terminator serves to delimit the scope of the START statement. END-START permits a conditional START statement to be nested in another conditional statement. END-START can also be used with an imperative START statement.
For more information, see Delimited scope statements.
When the KEY phrase is specified, the key data item used for the comparison is data-name-1.
When the KEY phrase is not specified, the key data item used for the EQUAL TO comparison is the prime RECORD KEY.
When START statement execution is successful, the RECORD KEY or ALTERNATE RECORD KEY with which data-name-1 is associated becomes the key of reference for subsequent READ statements.
Regardless of its category, data-name-1 is treated as an alphanumeric item for purposes of the comparison operation.
The file position indicator points to the first record in the file whose key field satisfies the comparison. If the operands in the comparison are of unequal lengths, the comparison proceeds as if the longer field were truncated on the right to the length of the shorter field. All other numeric and alphanumeric comparison rules apply, except that the PROGRAM COLLATING SEQUENCE clause, if specified, has no effect.
When START statement execution is successful, the RECORD KEY with which data-name-1 is associated becomes the key of reference for subsequent READ statements.
When START statement execution is unsuccessful, the key of reference is undefined.
When the KEY phrase is specified, data-name-1 must specify the RELATIVE KEY.
Whether or not the KEY phrase is specified, the key data item used in the comparison is the RELATIVE KEY data item. Numeric comparison rules apply.
The file position indicator points to the logical record in the file whose key satisfies the specified comparison.