EVALUATE command (COBOL)

The EVALUATE command provides a shorthand notation for a series of nested IF statements. The keywords cannot be abbreviated.

Read syntax diagramSkip visual syntax diagram
>>-EVALUATE--+-constant---+------------------------------------->
             +-expression-+   
             +-reference--+   
             +-TRUE-------+   
             '-FALSE------'   

   .-----------------------------------.   
   |                       .---------. |   
   V                       V         | |   
>----WHEN--| any_clause |----command-+-+------------------------>

>--+--------------------------+--END-EVALUATE--;---------------><
   |              .---------. |                    
   |              V         | |                    
   '-WHEN--OTHER----command-+-'                    

any_clause

|--+-+-ANY-------+------------------------------------------+---|
   | +-condition-+                                          |   
   | +-TRUE------+                                          |   
   | '-FALSE-----'                                          |   
   '-+-----+--+-constant--+--+----------------------------+-'   
     '-NOT-'  '-reference-'  '-+-THROUGH-+--+-constant--+-'     
                               '-THRU----'  '-reference-'       

Syntax diagram for the COBOL EVALUATE command
constant
A valid Debug Tool COBOL constant.
expression
A valid Debug Tool COBOL arithmetic expression.
reference
A valid Debug Tool COBOL reference.
condition
A simple relation condition.
command
A valid Debug Tool command.

Usage notes

Example

The following example shows an EVALUATE command and the equivalent coding for an IF command:
EVALUATE menu-input
  WHEN "0"
    CALL init-proc
  WHEN "1" THRU "9"
    CALL process-proc
  WHEN "R"
    CALL read-parms
  WHEN "X"
    CALL cleanup-proc
  WHEN OTHER
    CALL error-proc
END-EVALUATE;
The equivalent IF command:
IF (menu-input = "0") THEN
  CALL init-proc
ELSE
  IF (menu-input >= "1") AND (menu-input <= "9") THEN
    CALL process-proc
  ELSE
    IF (menu-input = "R") THEN
      CALL read-parms
    ELSE
      IF (menu-input = "X") THEN
        CALL cleanup-proc
      ELSE
        CALL error-proc
      END-IF;
    END-IF;
  END-IF;
END-IF;

Refer to the following topics for more information related to the material discussed in this topic.


Feedback