COBOL Manual for TNS and TNS/R Programs

Procedure Division Verbs
HP COBOL Manual for TNS and TNS/R Programs522555-006
9-211
SEARCH VARYING
Usage Considerations:
CONTINUE is Recommended Over NEXT SENTENCE
NEXT SENTENCE transfers control to the next period (.), while CONTINUE
transfers control to END-SEARCH. Either imperative-stmt-1, imperative-
stmt-2, or both can be CONTINUE statements.
Execution
The SEARCH VARYING statement specifies a serial search through elements of
the table referenced by table. In general terms, the search operation
successively increments the value of an index-name, which represents the
occurrence number of an element in the table, until either some condition
evaluates to TRUE or the occurrence number represented by the value of the
index-name exceeds the maximum defined for the table.
When the VARYING phrase is present, and if it specifies an index-name
associated with table (by its OCCURS clause), then that index-name is used for
the search. If it specifies an index-name not associated with table, or if it
specifies a separate integer data item or an index data item, the primary index of
table is used in the search (starting at its current setting), and these operations
occur:
°
If you specify an index-name associated with another table, the process
increments the occurrence number that index-name represents by the same
amount and at the same time as it increments the occurrence number the
primary index represents.
°
If you specify an index data item, the process increments the value of the item
by the same amount and at the same time as it increments the index
associated with table.
°
If you specify an integer data item, the process increments the value of the
item by 1 at the same time as it increments the index associated with table.
Without the VARYING phrase, the search varies the value of the primary index of
table (starting at its current setting). Any other indexes specified with table
remain unchanged.
If, when execution of the SEARCH statement begins, the value of the index-name
corresponds to an occurrence number greater than the one that identifies the last
element of the table, the at-end condition exists and the search operation
terminates immediately; otherwise, the search operation proceeds:
1. Each condition is evaluated, in the order in which they appear in the statement,
until one of them evaluates to TRUE or all of them evaluate to FALSE. For
each operand of a condition, the process of operand identification occurs just
prior to its use each time the operand participates in the determination of that
condition’s value. For details, see Condition Evaluation Rules.