The SEARCH statement searches a table for an element that satisfies the specified condition and adjusts the associated index to indicate that element.
Use format 1 (serial search) when the table that you want to search has not been sorted. Use format 1 to search a sorted table when you want to search serially through the table or you want to control subscripts or indexes.
Use format 2 (binary search) when you want to efficiently search across all occurrences in a table. The table must previously have been sorted, and you can sort the table with the format 2 SORT statement.
AT END and WHEN phrases
After imperative-statement-1 or imperative-statement-2 is executed, control passes to the end of the SEARCH statement, unless imperative-statement-1 or imperative-statement-2 ends with a GO TO statement.
The function of the AT END phrase is the same for a serial search and a binary search.
NEXT SENTENCE transfers control to the first statement following the closest separator period.
When NEXT SENTENCE is specified with END-SEARCH, control does not pass to the statement following the END-SEARCH. Instead, control passes to the statement after the closest following period.
For the format-2 SEARCH ALL statement, neither imperative-statement-2 nor NEXT SENTENCE is required. Without them, the SEARCH statement sets the index to the value in the table that matched the condition.
The function of the NEXT SENTENCE phrase is the same for a serial search and a binary search.
This explicit scope terminator delimits the scope of the SEARCH statement. END-SEARCH permits a conditional SEARCH statement to be nested in another conditional statement.
For more information, see Delimited scope statements.
The function of END-SEARCH is the same for a serial search and a binary search.