RAMESH KRISHNA REDDY mainframe discussion forum - cobol, db2,cics,jcl,file-aid,changeman,interview questions
Online Tutorials   | PREV  | TOP  | NEXT



Author : Kishore B.



EVALUATE 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 Exmaple 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. EVALUTE 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. This example is an example of decision table, calculates tax rate based on income, age and sex. First WHEN clause will satisfy if condition on income (>= 10000 and < 500000) is true, gender is “M” and age is in range of 20 to 60, if it is true, then MOVE statement after first when will get executed, and control come out of EVALUATE. If first WHEN condition becomes false, then control goes to second WHEN condi- tion and check the condition, whether that is true or false, if it is true, it will execute MOVE statement after the second WHEN condition. if second WHEN condition is false, then control will go to the MOVE statement coded after WHEN OTHER, here it wont check for true or false.



Previous chapter in COBOL tutorial Starting of COBOL tutorial Next chapter in COBOL tutorial

Visit COBOL books section in this site for good books

Home | Donations | Online Tutorials | Books | Entertainment | Contactme | privacy |  sql tutorial | jcl interview questions | JCL Tutorial | JCL Tutorial - chapter1 | JCL Tutorial - chapter2 | JCL Tutorial - chapter3 | JCL Tutorial - chapter4 | JCL Tutorial - chapter5 | JCL Tutorial - chapter6 | JCL Tutorial - chapter7 | JCL Tutorial - chapter8 | JCL Tutorial - chapter9 | JCL Tutorial - chapter10 | JCL Tutorial - chapter11