COBOL Manual for TNS and TNS/R Programs
Procedure Division Verbs
HP COBOL Manual for TNS and TNS/R Programs—522555-006
9-217
SEARCH ALL
°
When a data-name in the KEY phrase of the OCCURS clause associated with
table is referenced, or when a condition-name associated with such a data-
name is referenced, all preceding data-names (or the associated condition-
names) in the KEY phrase of that OCCURS clause must also be referenced.
When a SEARCH ALL statement does not meet these conditions, the compiler
issues a warning and does a linear search.
•
Additional Syntactic Constraints
If the WHEN phrase mentions either a data-name in the KEY phrase of the
OCCURS clause of the definition of table or a condition-name associated with a
data-name in that KEY phrase, all preceding data-names in the KEY phrase must
also be mentioned in the WHEN phrase. To illustrate, suppose you have this
OCCURS clause:
05 DEPT-TABLE OCCURS 500 TIMES
ASCENDING KEY IS DIV
SEC
DEPARTMENT
INDEXED BY NDEX, MDEX.
07 DIV PIC 9(4).
07 SEC PIC 9(3).
07 DEPARTMENT PIC 9(3).
88 R-AND-D VALUE 555.
You can search on DIV, or DIV and SEC, or all three keys. You cannot search on
SEC without searching on DIV, and you cannot search on DEPARTMENT without
searching on DIV and SEC.
•
Order of Table Elements
Verify that the table is ordered as specified in the ASCENDING or DESCENDING
phrase of the OCCURS clause of the table’s definition. If it is not, the result of the
search is undefined.
•
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.