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

Cobol - In an EVALUATE statement, can I give a complex condition on a when clause?




643
views
asked mar September 10, 2014 12:23 PM  

In an EVALUATE statement, can I give a complex condition on a when clause?


           

1 Answers



 
answered By Mswami   0  

Yes, You can mention the needed complex conditions using the WHEN statement rather than going for Nested-IF statements.

We can use EVALUATE instead of set of nested IF statements to test several conditions. We can use EVALUATE to implement case structure or decision table.

Example1 :

EVALUATE WS-INDICATOR
    WHEN “A”
      DISPLAY “This is Alphabetic filed” 
    WHEN “N”
     DISPLAY “This is Numeric filed” 
    WHEN “X”
     DISPLAY “This is Alpha numeric filed” 
    WHEN OTHER
     DISPLAY “Invalid indicator”
END-EVALUATE

This example evaluates WS-INDICATOR if WS-INDICATOR is ‘A’ displays “This is Alphabetic field”, if WS-INDICATOR is ‘N’ displays “This is Numeric filed”, if WS-INDICATOR is ‘X’ displays “This is Alpha numeric filed”. If WS-INDICATOR is not ‘A’ or ‘N’ or ‘X’ then it displays “Invalid indicator”.

EVALUATE Example 2 :

IF operand1 = operand4 AND operand2 = operand5
   Statements block1
ELSE 
   IF operand1 >= operand6 AND operand1 <= operand7 AND operand2 = operand8
   Statements block2
   ELSE 
   Statements block3
   END-IF
END-IF.

We can use following EVALUATE statement instead of above nested IF.

EVALUATE operand1 ALSO operand2
   WHEN operand4 ALSO opernad5
    Statements block1
   WHEN operand6   THRU   operand7    ALSO    operand8
    Statements block2
   WHEN OTHER
    Statements block3   
END-EVALUATE

Evaluate Example 3:

EVALUATE TRUE ALSO WS-GENDER ALSO WS_AGE

    WHEN WS-INCOME >= 10000 AND < 500000  ALSO  “M”  ALSO  20 THRU 60
          MOVE 13.5 TO WS-RATE 

    WHEN WS-INCOME >= 10000 AND < 500000  ALSO  “F”  ALSO  20 THRU 60  
          MOVE 12.0 TO WS-RATE 

    WHEN OTHER
          MOVE 0    TO WS-RATE

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