COBOL Manual for TNS/E Programs (H06.08+, J06.03+)

NOTE: Invalid-key conditions are taken care of by USE procedures instead of by INVALID KEY
phrases on the READ and REWRITE statements.
SEARCH
SEARCH scans a table for an element that satisfies a condition. If SEARCH finds the element,
SEARCH sets an index-name to the element’s offset value
Before executing SEARCH, the program must:
Initialize the relevant index-names and the table with appropriate values
Determine what criteria define successful completion of the search operation
A search proceeds by successively selecting candidates from among the elements of the table and
then evaluating the test conditions. For a variable-size table, only elements currently defined as a
part of the table can be searched. The last of these is the one referenced by the maximum occurrence
number, which is the value of the associated DEPENDING data item.
The search ends when a condition evaluates to TRUE or when every element of the table has been
searched, whichever occurs first.
SEARCH operates on a single table dimension. To search an entire multi-dimensional table, the
program must execute a SEARCH for each dimension, beginning with the outermost table level
and ending with the innermost table level.
SEARCH VARYING
SEARCH VARYING performs a serial search beginning with the current index setting. SEARCH
VARYING can also set the value of a data item or another index-name.
table
is the name of a data item described with an “OCCURS … INDEXED BY index-1 … KEY
…” clause. The search is done with index-1, which the search operation initializes to the
middle of the table before beginning to scan. Only the name of table can appear, qualified
if necessary, but not subscripted or reference modified.
indexer
is one of:
One of the index-names in the INDEXED phrase in the definition of table
An integer data item (which can, itself, be subscripted)
An index data item
428 Procedure Division Verbs