ANS85 

The EVALUATE Statement

The EVALUATE statement describes a multi-branch, multi-join structure. It can cause multiple conditions to be evaluated. The subsequent action of the runtime element depends on the results of these evaluations.

General Format


EVALUATE Statement

Syntax Rules

  1. The operands or the words TRUE and FALSE which appear before the first WHEN phrase of the EVALUATE statement are referred to individually as selection subjects and collectively, for all those specified, as the set of selection subjects.
  2. The operands or the words TRUE, FALSE, and ANY which appear in a WHEN phrase of an EVALUATE statement are referred to individually as selection objects and collectively, for all those specified in a single WHEN phrase, as the set of selection objects.
  3. The words THROUGH and THRU are equivalent.
  4. Two operands connected by a THROUGH phrase must be of the same class. The two operands thus connected constitute a single selection object.
  5. The number of selection objects in each set of selection objects must be equal to the number of selection subjects.
  6. Each selection object in a set of selection objects must correspond to the selection subject having the same ordinal position in the set of selection subjects according to the following rules:
    1. Identifiers, literals, or arithmetic expressions appearing in a selection object must be valid operands for comparison to the corresponding operand in the set of selection subjects. (See the topic Relation Condition in the chapter Procedure Division.)
    2. Condition-1, condition-2, or the words TRUE or FALSE appearing as a selection object must correspond to a conditional expression or the words TRUE or FALSE in the set of selection subjects.
    3. The word ANY can correspond to a selection subject of any type.
    4. VSC2MF Where identifiers are permitted, they can reference floating-point data items.
    5. VSC2MF Where numeric literals are permitted, floating-point literals are permitted.
    6. VSC2MF Where identifiers are permitted, they can reference pointer data items.
  7. A selection object is a partial-expression if the leftmost portion of the selection object is a relational operator, a class condition without the identifier, a sign condition without the identifier, or a sign condition without the arithmetic expression.
  8. ISO2002MF If partial-expression-1 or partial-expression-2 is specified as a selection object, it must correspond to a selection subject that is an identifier, a literal or an arithmetic expression. Partial-expression-1 and partial-expression-2 must be a sequence of COBOL words which, when following the corresponding selection subject, make the resultant text a valid conditional expression.

General Rules

  1. The execution of the EVALUATE statement operates as if each selection subject and selection object were evaluated and assigned a numeric or nonnumeric value, a range of numeric or nonnumeric values, or a truth value. These values are determined as follows:
    1. Any selection subject specified by identifier-1, identifier-2, and any selection object specified by identifier-3, identifier-5, without either the NOT or the THROUGH phrases, are assigned the value and class of the data item referenced by the identifier.
    2. Any selection subject specified by literal-1, literal-2, and any selection object specified by literal-3, literal-5, without either the NOT or the THROUGH phrases, are assigned the value and class of the specified literal. If literal-3, literal-5, is the figurative constant ZERO, it is assigned the class of the corresponding selection subject.
    3. Any selection subject in which expression-1, expression-2, is specified as an arithmetic expression and any selection object, without either the NOT or the THROUGH phrases, in which arithmetic-expression-1, arithmetic-expression-3, is specified are assigned a numeric value according to the rules for evaluating an arithmetic expression. (See the topic Arithmetic Expressions in the chapter Procedure Division.)
    4. Any selection subject in which expression-1, expression-2 is specified as a conditional expression and any selection object in which condition-1, condition-2, is specified are assigned a truth value according to the rules for evaluating conditional expressions. (See the topic Conditional Expressions in the chapter Procedure Division.)
    5. Any selection subject or any selection object specified by the words TRUE or FALSE is assigned a truth value. The truth value "true" is assigned to those items specified with the word TRUE, and the truth value "false" is assigned to those items specified with the word FALSE.
    6. Any selection object specified by the word ANY is not further evaluated.
    7. If the THROUGH phrase is specified for a selection object, without the NOT phrase, the range of values is all values which, when compared to the selection subject, are greater than or equal to the first operand and less than or equal to the second operand according to the rules for comparison. (See the topic Relation Condition in the chapter Procedure Division.
    8. If the NOT phrase is specified for a selection object, the values assigned to that item are all values not equal to the value, or range of values, which would have been assigned to the item had the NOT phrase not been specified.
  2. The execution of the EVALUATE statement then proceeds as if the values assigned to the selection subjects and selection objects were compared to determine if any WHEN phrase satisfies the set of selection subjects. This comparison proceeds as follows:
    1. Each selection object in the set of selection objects for the first WHEN phrase is compared to the selection subject having the same ordinal position in the set of selection subjects.
      1. If the items being compared are assigned numeric or nonnumeric values, or a range of numeric or nonnumeric values, the comparison is satisfied if the value, or one of the range of values, assigned to the selection object is equal to the value assigned to the selection subject according to the rules for comparison. (See the topic Relation Condition in the chapter Procedure Division.)
      2. If the items being compared are assigned truth values, the comparison is satisfied if the items are assigned the identical truth value.
      3. If the selection object being compared is specified by the word ANY, the comparison is always satisfied regardless of the value of the selection subject.
    2. If the above comparison is satisfied for every selection object in the set of selection objects being compared, the WHEN phrase containing that set of selection objects is selected as the one satisfying the set of selection subjects.
    3. If the above comparison is not satisfied for one or more selection objects in the set of selection objects being compared, that set of selection objects does not satisfy the set of selection subjects.
    4. This procedure is repeated for subsequent sets of selection objects, in the order of their appearance in the source element, until either a WHEN phrase satisfying the set of selection subjects is selected or until all sets of selection objects are exhausted.
  3. After the comparison operation is completed, execution of the EVALUATE statement proceeds as follows:
    1. If a WHEN phrase is selected, execution continues with the first imperative-statement-1 following the selected WHEN phrase.
    2. If no WHEN phrase is selected and a WHEN OTHER phrase is specified, execution continues with imperative-statement-2.
    3. The scope of execution of the EVALUATE statement is terminated when execution reaches the end of the scope of the selected WHEN phrase or WHEN OTHER phrase or when no WHEN phrase is selected and no WHEN OTHER phrase is specified.
  4. ISO2002MF If the selection object is specified by partial-expression-1 or partial-expression-2, the corresponding selection subject is considered to be the word TRUE. The selection object is considered to be condition-1 or condition-2 respectively, where condition-1 or condition-2 is the conditional expression resulting from partial expression-1 or partial-expression-2 following the original corresponding selection-subject-1 or selection-subject-2 respectively.