COBOL Manual for TNS and TNS/R Programs
Procedure Division Verbs
HP COBOL Manual for TNS and TNS/R Programs—522555-006
9-71
EVALUATE
The EVALUATE statement extends the “case” statement concept by allowing
several selection subjects and matching objects—the equivalent of a decision
table. The EVALUATE statement in Example 9-21 uses the values of two distinct
subjects to make its selection.
The selection objects (the “0” and “1 THRU 2” of Example 9-21) are not restricted
to being literals or ranges of literals; they can also be (for example) condition
names, identifiers, and arithmetic expressions.
The WHEN OTHER phrase is commonly used as the mechanism for handling
errors, enabling the program to detect invalid values for subjects and improper
specification of objects.
•
Subject-Object Correspondence
Every object-list must have an object for every subject in the
subject-list. Each object in an object-list must correspond to the
subject that has the same ordinal position in the subject-list. The rules that
determine whether a subject and object correspond are:
°
The object value ANY corresponds to any subject value.
°
An object that is a condition or the value TRUE or FALSE corresponds to a
subject that is a conditional expression or the value TRUE or FALSE.
°
An object composed of identifiers, literals, or arithmetic expressions
corresponds to a subject if the value of the object is a valid operand for
comparison to the subject.
Example 9-21. EVALUATE Statement With Two Distinct Subjects
EVALUATE DEDUCTIONS ALSO SALARY
WHEN 0 ALSO 0 THRU 14999.99 PERFORM XXA
WHEN 0 ALSO 15000 THRU 29999.99 PERFORM YYA
WHEN 0 ALSO 30000 THRU 49999.99 PERFORM ZZA
WHEN 1 THRU 2 ALSO 0 THRU 19999.99 PERFORM XXB
WHEN 1 THRU 2 ALSO 20000 THRU 69999.99 PERFORM YYB
WHEN 1 THRU 2 ALSO 70000 THRU 99999999 PERFORM ZZB
WHEN OTHER PERFORM FURTHER-ANALYSIS
END-EVALUATE
Example 9-22. EVALUATE Statement as a Decision Table
EVALUATE XXX ALSO "GONE" ALSO ( A + B ) / C ALSO X = Y
WHEN 5 ALSO ANY ALSO 25 ALSO TRUE
PERFORM PROC-A
WHEN 10 THRU 30 ALSO YYY ALSO 2 ALSO FALSE
PERFORM PROC-B
WHEN OTHER ADD 1 TO VACUOUS-COUNT
END-EVALUATE