COBOL Manual for TNS and TNS/R Programs

Procedure Division Verbs
HP COBOL Manual for TNS and TNS/R Programs522555-006
9-209
SEARCH
9 Procedure Division Verbs
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.
Form Description
SEARCH VARYING
Performs a serial search beginning with the current index. Can also
set the value of a data item or another index-name.
SEARCH ALL
Performs a binary search until it finds the element satisfying the
conditions or has searched every element of the table.
table indexerSEARCH VARYING
AT
WHEN condition
imperative-stmt-1
END-SEARCH
END
SENTENCE
imperative-stmt-2
NEXT
VST206.vsd