COBOL EVALUATE TRUE

 

EVALUATE TRUE
 
The following COBOL program depicts the use of 
EVALUATE TRUE 
 
 
       PROGRAM-ID. PGM002.
       AUTHOR. MAINFRAMEWIZARD.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 WS-SUB   PIC 9  VALUE ZEROS.
       PROCEDURE DIVISION.
       10000-MAIN-PARA.
             MOVE 5 TO WS-SUB.
             EVALUATE TRUE
                 WHEN WS-SUB>4
                  DISPLAY 'WS-SUB IS GREATER THAN 4'
                 WHEN WS-SUB>5
                  DISPLAY 'WS-SUB IS GREATER THAN 5'
                 WHEN OTHER
                  DISPLAY 'NO CONDITION MET'
             END-EVALUATE
             STOP RUN.
 
 
 
The ouput of the above program is 
 
 
WS-SUB IS GREATER THAN 4                                                                                                 
 
 
 
Note:- Control comes out of EVALUATE as soon as first satisfying condition is met.
 
If in the above case first condition was WS-SUB>1 and second condition was WS-SUB>2
then the control would have come out of EVALUATE as soon as WS-SUB>1 condition is met.
 
Try it yourself!!