EVALUATE Statement

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).

Note: This manual entry includes code examples and highlights for first-time users following the General Rules section.

General Format

EVALUATE  {subject}  [ ALSO {subject} ] ...
          {TRUE   }         {TRUE   }
          {FALSE  }         {FALSE  }

  { { WHEN obj-phrase [ ALSO obj-phrase ] ... } ... 

           statement-1 } ...

  [ WHEN OTHER statement-2 ]

  [ END-EVALUATE ]

obj-phrase has the following format:

  { ANY                                  }
  { TRUE                                 }
  { FALSE                                }
  { [=] cond-obj                         }
  { [NOT =] obj-item [ {THRU   } obj-item ]}
  {                  {THROUGH}           }
  { < obj-item                           }
  { IS LESS THAN obj-item                }
  { <= obj-item                          }
  { IS LESS THAN OR EQUAL TO obj-item    }
  { = obj-item                              }
  { IS EQUAL TO obj-item                    }
  { EQUALS obj-item                         }
  { > obj-item                              }
  { IS GREATER THAN obj-item                }
  { EXCEEDS obj-item                        }
  { >= obj-item                             }
  { IS GREATER THAN OR EQUAL TO obj-item    }
  { <> obj-item                             }
  { IS UNEQUAL TO obj-item                  }

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:
    1. obj-item must be a valid operand for comparison to the corresponding subject.
    2. TRUE, FALSE, or cond-obj as an object must correspond to TRUE, FALSE, or a conditional expression as the subject.
    3. 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:
    1. 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.
    2. 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.
    3. Any subject or object that is a conditional expression is assigned a truth value according to the rules for evaluating conditional expressions.
    4. Any subject or object specified by the words TRUE or FALSE is assigned a truth value corresponding to that word.
    5. Any object specified by the word ANY is not evaluated.
    6. 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.
    7. 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:
    1. 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.
    2. If the items being compared are assigned truth values, the comparison is satisfied if the truth values are the same.
    3. 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 WHEN verb is accepted as an implied END-IF or END-PERFORM for any and all preceding IF and PERFORM statements that do not have corresponding END- statements.
  8. 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.

Code Example 1:

EVALUATE AGE
   WHEN 56 THRU 99  PERFORM  SENIOR_PROSPECT
   WHEN 40 THRU 55  PERFORM  MATURE_PROSPECT
   WHEN 21 THRU 39  PERFORM  YOUNG_PROSPECT
   WHEN OTHER       PERFORM  NOT_A_PROSPECT
END-EVALUATE.

Code Example 2:

EVALUATE INCOME ALSO TRUE
   WHEN  20000 THRU 39999  ALSO RISK_CLASS = "A"
      PERFORM LOW_INCOME_PROSPECT
   WHEN  40000 THRU 59999  ALSO RISK_CLASS = "A"
      PERFORM  MID_INCOME_PROSPECT
   WHEN  60000 THRU 999999 ALSO RISK_CLASS = "A"
      PERFORM  HIGH_INCOME_PROSPECT
   WHEN  60000 THRU 999999 ALSO NOT RISK_CLASS = "A"
      PERFORM  HIGH_INCOME_HIGH_RISK_PROSPECT
   WHEN  OTHER
      PERFORM UNCLASSIFIED_PROSPECT
END-EVALUATE.

Highlights for First-time Users

  1. Statement subjects (associated with the EVALUATE phrase) and statement objects (associated with the WHEN phrase) must be equal in number, correspond by position and be valid operands for comparison. Note the number and order of subjects in example 2 and the correspondent number and position of WHEN objects.
  2. If all of the conditions in a WHEN phrase match, the associated imperative statement is executed. None of the remaining WHEN phrases is evaluated. Program execution then falls through to the end of the EVALUATE statement.
  3. The WHEN OTHER phrase is an optional phrase for the handling of all remaining cases (the set of possible conditions not explicitly tested for by the preceding WHEN phrases). The WHEN OTHER phrase, if present, must be the last WHEN phrase in the statement.
  4. The words TRUE and FALSE may be used in the subject or object phrase to specify a literal truth condition.
  5. The word ANY may be used in the WHEN phrase to specify an unconditional match with the corresponding item in the subject phrase.
  6. The word NOT may be used in the WHEN phrase to negate its associated condition.
  7. The word THROUGH or THRU may be used in the WHEN phrase to describe a range of values. When combined with NOT, THRU describes an excluded set of values. For example, NOT 10 THRU 20 means that any object holding a value from 10 to 20, including the numbers 10 and 20, will result in a FALSE, or no match evaluation.