


The EVALUATE statement causes multiple conditions to be evaluated. The subsequent action of the program depends on the results of these evaluations.
The EVALUATE statement is very similar to the CASE construct common in many other programming languages. The EVALUATE/CASE construct provides the ability to selectively execute one of a set of instruction alternatives based on the evaluation of a set of choice alternatives.
EVALUATE extends the power of the typical CASE construct by allowing multiple data items and conditions to be named in the EVALUATE phrase (see code example 2).
EVALUATE {subject} [ ALSO {subject} ] ...
{TRUE } {TRUE }
{FALSE } {FALSE }
{ { WHEN obj-phrase [ ALSO obj-phrase ] ... } ...
statement-1 } ...
[ WHEN OTHER statement-2 ]
[ END-EVALUATE ]
{ ANY }
{ TRUE }
{ FALSE }
{ cond-obj }
{ [NOT] obj-item [ {THRU } obj-item ]}
{ {THROUGH} }Syntax Rules
1. Subject may be a literal, data item, arithmetic expression, or conditional expression.
2. Cond-obj is a conditional expression.
3. Obj-item may be a literal, data item, or arithmetic expression.
4. Statement-1 and statement-2 are imperative statements.
5. Before the first WHEN phrase, subject and the words TRUE and FALSE are called "subjects," and all the subjects together are called the "subject set".
6. The operands and the words TRUE, FALSE, and ANY which appear in a WHEN phrase are called "objects," and the collection of objects in a single WHEN phrase is called the "object set".
7. The words THROUGH and THRU are equivalent. Two obj-items connected by a THROUGH phrase must be of the same class. They are treated as a single object.
8. The number of objects within each object set must match the number of subjects in the subject set.
9. Each object within an object set must correspond to the subject having the same ordinal position as in the subject set. For each pair:
a) Obj-item must be a valid operand for comparison to the corresponding subject.
b) TRUE, FALSE, or cond-obj as an object must correspond to TRUE, FALSE, or a conditional expression as the subject.
c) ANY may correspond to any type of subject.
General Rules
1. The EVALUATE statement operates as if each subject and object were evaluated and assigned a value or range of values. These values may be numeric, nonnumeric, truth values, or ranges of numeric or nonnumeric values. These values are determined as follows:
a) Any subject or object that is a data item or literal, without either the THROUGH or the NOT phrase, is assigned the value and class of that data item or literal.
b) Any subject or object that is an arithmetic expression, without either the THROUGH or the NOT phrase, is assigned a numeric value according to the rules for evaluating arithmetic expressions.
c) Any subject or object that is a conditional expression is assigned a truth value according to the rules for evaluating conditional expressions.
d) Any subject or object specified by the words TRUE or FALSE is assigned a truth value corresponding to that word.
e) Any object specified by the word ANY is not evaluated.
f) If the THROUGH phrase is specified for an object, without the NOT phrase, the range of values includes all permissible values of the corresponding subject that are greater than or equal to the first operand and less than or equal to the second operand, according to the rules for comparison.
g) If the NOT phrase is specified for an object, the values assigned to that object are all permissible values of the corresponding subject not equal to the value, or range of values, that would have been assigned had the NOT phrase been omitted.
2. The EVALUATE statement then proceeds as if the values assigned to the subjects and objects were compared to determine if any WHEN phrase satisfies the subject set. Each object within the object set for the first WHEN phrase is compared to the subject having the same ordinal position within the subject set. The comparison is satisfied if one of the following is true:
a) If the items being compared are assigned numeric or nonnumeric values, the comparison is satisfied if the value (or one of the range of values) assigned to the object is equal to the value assigned to the subject.
b) If the items being compared are assigned truth values, the comparison is satisfied if the truth values are the same.
c) If the object is the word ANY, the comparison is always satisfied.
3. If the comparison is satisfied for every object within the object set, the corresponding WHEN phrase is selected.
4. If the comparison is not satisfied for one or more objects within the object set, the procedure repeats for the next WHEN phrase. This is repeated until a WHEN phrase is selected or all the object sets have been tested.
5. If a WHEN phrase is selected, the corresponding statement-1 is executed.
6. If no WHEN phrase is selected and a WHEN OTHER phrase is specified, statement-2 is executed. If no WHEN OTHER phrase is present, control transfers to the end of the EVALUATE statement.
7. The scope of execution of the EVALUATE statement is terminated when the end of statement-1 or statement-2 is reached, or when no WHEN phrase is selected and no WHEN OTHER phrase is specified.
More: