EVALUATE Statement [ HP COBOL II Reference Manual ]

HP COBOL II Reference Manual

EVALUATE Statement 

The EVALUATE statement adds a multi-condition case construct to COBOL.
This statement causes a set of subjects to be evaluated and compared with
a set of objects.  The results of these evaluations determine the
subsequent sequence of code execution.

This statement has the following format:

	       Click here to view figure.
Subjects and Objects 

The operands or the words TRUE and FALSE that appear before the first
WHEN phrase of the EVALUATE statement are referred to individually as
subjects.  Collectively, they are referred to as the set of subjects.

The operands or the words TRUE, FALSE, and ANY that appear in a WHEN
phrase of an EVALUATE statement are individually called objects.
Collectively, they are called the set of objects.

The words THROUGH and THRU are equivalent.

Two operands connected by a THROUGH phrase must be of the same class.
The two connected operands constitute a single object.

The number of objects within each set of objects must be equal to the
number of subjects.

Correspondence Between Subjects and Objects.  A subject-object pair
consists of a subject and object having the same ordinal position within
each set.  Each pair must conform to the following rules:

 *  Identifiers, literals, and arithmetic expressions must be valid
    operands for a comparison between the subject and object.

 *  Conditions, or the words TRUE or FALSE appearing as an object must
    correspond to a conditional expression or the words TRUE or FALSE.

 *  The word ANY may correspond to a selection subject of any type.

Evaluation of Subjects and Objects.  Execution of the EVALUATE statement
operates as if each subject and 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:

 *  Any subject or object specified by an identifier, without either the
    NOT or the THROUGH phrases, is assigned the value and class of the
    data item referenced by the identifier.

 *  Any subject or object specified by a literal, without either the NOT
    or the THROUGH phrases, is assigned the value and class of the
    specified literal.  When an object is assigned the figurative
    constant ZERO, it is assigned the class of the corresponding subject.

 *  Any subject or object in which an expression is specified as an
    arithmetic expression without either the NOT or the THROUGH phrases,
    is assigned a numeric value according to the rules for evaluating an
    arithmetic expression.  (Refer to Chapter 8, under "Arithmetic
    Expressions".)

 *  A subject or object specified by a conditional expression is assigned
    a truth value according to the rules for evaluating conditional
    expressions.  (Refer to Chapter 8, "Conditional Expressions".)

 *  A subject or object specified by the words TRUE or FALSE is assigned
    the appropriate truth value.

 *  No further evaluation is done for an object specified by the word
    ANY.

 *  If the THROUGH phrase is specified for an object, without the NOT
    phrase, the range of values includes all values of the subject that
    are greater than or equal to the first operand and less than or equal
    to the second operand.

 *  If the NOT phrase is specified for an object, the values assigned to
    that item are all values that are not equal to the value, or included
    in the range of values, that would have been assigned to the item
    without the NOT phrase.

Refer to Chapter 8, "Relation Conditions," for more information on NOT
phrases.

Comparison Operation of EVALUATE 

The execution of the EVALUATE statement proceeds as if the values
assigned to the subjects and objects were compared, to determine if any
WHEN phrase satisfies the set of subjects.  This comparison proceeds as
follows:

   1.  A subject-object pair comparison is satisfied if the following
       conditions are true:

       a.  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 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 items are assigned the
           identical truth values.

       c.  If the object being compared is specified by the word ANY, the
           comparison is always satisfied, regardless of the value of the
           subject.

   2.  If the above comparison is satisfied for every object within the
       set of objects being compared, the first WHEN phrase for which
       each subject-object pair comparison is satisfied is selected as
       the one that satisfies the set of subjects.

   3.  If the above comparison is not satisfied for one or more objects
       within the set of objects being compared, that set of objects does
       not satisfy the set of subjects.

   4.  This procedure is repeated for subsequent sets of objects in the
       order of their appearance in the source program.  The comparison
       operation continues until either a WHEN phrase that satisfies the
       set of subjects is selected, or until all sets of objects are
       exhausted.

Execution of EVALUATE 

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 following the selected WHEN phrase.

   2.  If no WHEN phrase is selected and a WHEN OTHER phrase is
       specified, execution continues with the imperative statement
       following the WHEN OTHER phrase.

   3.  The execution of the EVALUATE statement is terminated when
       execution reaches the end of the imperative statement of the
       selected WHEN phrase, or when no WHEN phrase is selected and no
       WHEN OTHER phrase is specified.

Examples 

     EVALUATE HOURS-WORKED ALSO EXEMPT

        WHEN 0 ALSO ANY PERFORM NO-PAY
        WHEN NOT 0 ALSO "Y" PERFORM SALARIED
        WHEN 1 THRU 40 ALSO "N" PERFORM HOURLY-PAY
        WHEN NOT 1 THRU 40 ALSO "NO" PERFORM OVERTIME-PAY
        WHEN OTHER
             DISPLAY HOURS-WORKED
             DISPLAY EXEMPT
             MOVE 0 TO HOURS-WORKED
     END-EVALUATE

     EVALUATE GRADE > 3.0 ALSO COLLEGE-CODE

        WHEN TRUE ALSO "01"
            PERFORM DEANS-LIST-AGGIES
        WHEN TRUE ALSO "02"
            PERFORM DEANS-LIST-S-AND-H
        WHEN TRUE ALSO "03"
            PERFORM DEANS-LIST-ENG
        WHEN TRUE ALSO ANY
            PERFORM MISC-LIST.