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

Execution
The SEARCH ALL statement specifies a search through the elements of a table. The results of
a SEARCH ALL statement are predictable only when both of these are true:
The data in the table are ordered in the manner described in the KEY phrase of the
OCCURS clause that describes the table.
The condition specified in the WHEN phrase (called the “target condition”) evaluates to
TRUE only during the consideration of exactly one of the table elements.
The search operation varies the value of the first index-name that appears in the INDEXED
phrase of the OCCURS clause describing the table. The search operation insures that the
varying value always corresponds to an occurrence number defined for the table.
The SEARCH ALL operation proceeds in a binary fashion, successively setting the index-name
to correspond to different table elements and evaluating the target condition. For each operand
of the target condition, the process of operand identification occurs just before its use each
time the operand participates in the determination of the value of the target condition.
When Exactly One Matching Element Is Found
When the target condition evaluates to TRUE, the search all operation terminates and the
value of the index-name corresponds to the element under consideration. If the NEXT
SENTENCE phrase is specified, control passes to the next executable sentence; otherwise,
imperative-stmt-2 is executed and then control passes to the end of the SEARCH ALL
statement (unless execution of imperative-stmt-2 explicitly transfers control elsewhere
using a GO TO statement).
If more than one element satisfies the condition, the index can point to any one of them.
When No Matching Element Is Found
When the value of the target condition is FALSE, the search operation terminates with the
at-end condition and the value of the index-name is undefined. If the AT END phrase is
specified, imperative-stmt-1 is executed. Control passes to the end of the SEARCH
statement (unless execution of imperative-stmt-2 explicitly transfers control elsewhere
using a GO TO statement).
Tables Defined With a DEPENDING Phrase
For a variable-occurrence table, only those elements currently defined as a part of the table
can be candidates. The last of these is the one specified by the maximum occurrence number,
which is the value of the associated DEPENDING data item.
Index Values
During the search operation, the first index-name appearing in the INDEXED phrase of the
OCCURS clause describing the table is varied so that its value always corresponds to an
occurrence number defined for the table. The value of this index-name at the start of execution
of the SEARCH statement is immaterial.
Example 132 SEARCH ALL Statement
WORKING-STORAGE SECTION.
01 COMMANDS.
05 FILLER PIC X(6) VALUE "ADD".
05 FILLER PIC X(6) VALUE "DELETE".
05 FILLER PIC X(6) VALUE "EXIT".
05 FILLER PIC X(6) VALUE "LIST".
...
01 COMMANDS-IN-TABLE REDEFINES COMMANDS.
05 COMMAND-ENTRIES PIC X(6) OCCURS 6 TIMES
ASCENDING KEY IS COMMAND-ENTRIES
INDEXED BY TABLE-INDEX.
SEARCH 435