COBOL Manual for TNS/E Programs (H06.08+, J06.03+)
Example 131 SEARCH VARYING Statement
WORKING-STORAGE SECTION.
01 COMMANDS.
05 FILLER PIC X(6) VALUE "ADD".
05 FILLER PIC X(6) VALUE "DELETE".
...
01 COMMANDS-IN-TABLE REDEFINES COMMANDS.
05 COMMAND-ENTRIES PIC X(6) OCCURS 6 TIMES
INDEXED BY TABLE-INDEX.
77 COMMAND-IN PIC X(6).
...
PROCEDURE DIVISION.
...
SET TABLE-INDEX TO 1
SEARCH COMMAND-ENTRIES VARYING TABLE-INDEX
AT END
PERFORM COMMAND-ERROR-ROUTINE
WHEN COMMAND-ENTRIES(TABLE-INDEX) = COMMAND-IN
CONTINUE
END-SEARCH
...
SEARCH ALL
SEARCH ALL performs a binary search on a table. The table must be declared with a KEY phrase
in its OCCURS clause.
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.
imperative-stmt-1
is an imperative statement to be executed when an at-end condition is detected (the end of the
search is reached with no entry satisfying all specified conditions).
432 Procedure Division Verbs










