Evaluate Verb in COBOL

Introduction

  • Evaluate verb is an alternative for the series of IF-ELSE statements.
  • This verb is useful to evaluate more than one condition.
  • Evaluate verb is equivalent to SWITCH statement in C programs.

Example : Program to demonstrate Evaluate Verb

IDENTIFICATION DIVISION.
PROGRAM-ID. EV.

DATA DIVISION.
   WORKING-STORAGE SECTION.
   01 A PIC 9 VALUE 0.
   
PROCEDURE DIVISION.
   MOVE 8 TO A.
   
   EVALUATE TRUE
      WHEN A > 6
         DISPLAY 'A GREATER THAN 6'

      WHEN A < 0
         DISPLAY 'A LESS THAN 0'

      WHEN OTHER
         DISPLAY 'INVALID VALUE OF A'
   END-EVALUATE.
   
STOP RUN.


Output:
A GREATER THAN 6