EVALUATE Statement [ HP COBOL II/XL Reference Manual ] MPE/iX 5.0 Documentation
 
  
  
  
 
HP COBOL II/XL 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.
Syntax 
            
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 (TRUE or FALSE). 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 (TRUE or FALSE) 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,
              nonnumeric, 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.
       [REV BEG]
       If a WHEN phrase is followed by other WHEN phrases with no
       intervening imperative statement, the WHEN conditions are ORed
       together.  In other words, if any of the WHEN phrases is selected,
       the first imperative statement that follows is executed, even if
       that imperative statement is part of a following WHEN phrase.  See
       the following section for an example.
       Use the CONTINUE statement to indicate no operation on a WHEN
       clause.  See the following section for examples.[REV END]
   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 
[REV BEG]
The following example shows an EVALUATE statement with two data items
(HOURS-WORKED and EXEMPT) as subjects:[REV END]
     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 "N" PERFORM OVERTIME-PAY
        WHEN OTHER                  DISPLAY HOURS-WORKED
                                    DISPLAY EXEMPT
                                    MOVE 0 TO HOURS-WORKED
     END-EVALUATE.
[REV BEG]
The following shows a relation condition (GRADE > 3.0) and a data item
(COLLEGE-CODE) as the subjects of an EVALUATE:[REV END]
     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
     END-EVALUATE.
[REV BEG]
The following shows two equivalent EVALUATE statements that illustrate
that subjects and objects must be of the same type.  The first EVALUATE
statement shows the truth value, TRUE, as the subject and several
condition name conditions as objects.  The second shows the data item
INPUT-FLAG as the subject and nonnumeric literals as objects.  Notice
also that if INPUT-FLAG is "C", the EVALUATE statement executes the
CONTINUE statement, which simply continues execution at the statement
following the EVALUATE statement:
     WORKING-STORAGE SECTION.
     01  INPUT-FLAG   PIC X VALUE SPACE.
         88  INPUT-YES      VALUE "Y".
         88  INPUT-NO       VALUE "N".
         88  INPUT-QUIT     VALUE "Q".
         88  INPUT-CONTINUE VALUE "C".
               :
     EVALUATE TRUE
        WHEN INPUT-CONTINUE CONTINUE
        WHEN INPUT-YES      MOVE PROD-NO TO OUTPUT-REC
        WHEN INPUT-NO       MOVE SPACES  TO OUTPUT-REC
        WHEN INPUT-QUIT     PERFORM TERMINATION-ROUTINE
        WHEN OTHER          PERFORM GET-INPUT
     END-EVALUATE.
[REV END]
[REV
BEG]
     EVALUATE INPUT-FLAG
        WHEN "Y"   MOVE PROD-NO TO OUTPUT-REC
        WHEN "N"   MOVE SPACES  TO OUTPUT-REC
        WHEN "Q"   PERFORM TERMINATION-ROUTINE
        WHEN "C"   CONTINUE
        WHEN OTHER PERFORM GET-INPUT
     END-EVALUATE.
The following example shows two WHEN phrases without an intervening
imperative statement.  If either the first or the second WHEN phrase is
selected, that is, if NUMBER-OF-THINGS is either 1 or 2, the DISPLAY
statement after WHEN 2 is executed:
     EVALUATE NUMBER-OF-THINGS
        WHEN 1
        WHEN 2  DISPLAY "The value is 1 or 2"
        WHEN 3  STOP RUN
        WHEN OTHER DISPLAY "Input again."
     END-EVALUATE.
[REV END]
 
  
  
  
 
 MPE/iX 5.0 Documentation