Home > Software > Mainframe > Cobol
Interview Questions   Tutorials   Discussions   Programs   

Cobol - What are the different forms of EVALUATE statement?




448
views
asked mar August 3, 2014 02:01 AM  

What are the different forms of EVALUATE statement?


           

1 Answers



 
answered By Mswami   0  
Evaluate is like a case statement and can be used to replace nested Ifs. The difference between EVALUATE and case is that no 'break' is required for EVALUATE i.e. control comes out of the EVALUATE as soon as one match is made.

General Syntax:
EVALUATE subject-1 (ALSO subject2..)
          WHEN object-1 (ALSO object2..)
               WHEN object-3 (ALSO object4..)
               WHEN OTHER imperative statement
END-EVALUATE
1.Number of Subjects in EVALUATE clause should be equal to number of objects in every WHEN clause.
2.Subject can be variable, expression   or the keyword TRUE/ FLASE and respectively objects can be values, TRUE/FALSE or any condition.
3.If none of the WHEN condition is satisfied, then WHEN OTHER path will be executed.

Different forms:

EVALUATE                     &n bsp;                            EVALUATE SQLCODE ALSO FILE-STATUS
       WHEN A=B AND C=D                                WHEN 100 ALSO '00'
                    imperative stmt                        &n bsp;                       imperative stmt  
WHEN (D+X)/Y = 4                          ;             WHEN -305 ALSO '32'
            imperative stmt                        &n bsp;                       imperative stmt
WHEN OTHER                        & nbsp;                     WHEN OTHER
        imperative stmt                        &n bsp;                       imperative stmt
END-EVALUATE                     &nbs p;                    END-EVALUATE



EVALUATE SQLCODE ALSO A=B            EVALUATE SQLCODE ALSO TRUE
WHEN 100 ALSO TRUE                               WHEN 100 ALSO A=B
             imperative stmt                        &n bsp;                imperative stmt
WHEN -305 ALSO FALSE                              WHEN -305 ALSO (A/C=4)
           imperative stmt                        &n bsp;                   imperative stmt
END-EVALUATE                     &nbs p;                 END-EVALUATE
flag   
   add comment

Your answer

Join with account you already have

FF

Preview


Ready to start your tutorial with us? That's great! Send us an email and we will get back to you as soon as possible!

Alert