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.
DISPLAY “This is Alphabetic filed”
DISPLAY “This is Numeric filed”
DISPLAY “This is Alpha numeric filed”
DISPLAY “Invalid indicator”
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
IF operand1 >= operand6 AND operand1 <= operand7 AND operand2 = operand8
We can use following EVALUATE statement instead of above nested IF.
EVALUTE operand1 ALSO operand2
WHEN operand4 ALSO opernad5
WHEN operand6 THRU operand7 ALSO operand8
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
MOVE 0 TO WS-RATE
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.