EVALUATE statement is used for conditional processing which helps in eliminating a series of nested IF statements to test several conditions. The EVALUATE statement is very similar to the CASE construct common in many other programming languages. If none of the EVALUATE satisfies, by default the statements coded under WHEN OTHER will be executed and control transfers to the next executable statement after ending of EVALUATE.
EVALUATE {subject} [ ALSO {subject} ] ... {TRUE } {TRUE } {FALSE } {FALSE } { { WHEN obj-phrase [ ALSO obj-phrase ] ... } ... statement-1 } ... [ WHEN OTHER statement-2 ] [ END-EVALUATE ] Subject has the following format { IDENTIFIER } { LITERAL } { COND EXPRESSION } { ARITH EXPRESSION } Obj-phrase has the following format { ANY } { TRUE } { FALSE } { cond-obj } { [NOT] obj-item [ {THRU } obj-item ]} { {THROUGH} }
EVALAUTE can be divided into below types based on its usage in the program.
Example 1: Simple EVALUATE EVALUATE WS-RENT-APTNO WHEN 1 PERFORM 100-RENT-REPORT WHEN 2 PERFORM 200-RENT-REPORT WHEN OTHER PERFORM 999-ERROR-REPORT END-EVALUATE.
Example 2: EVALUATE TRUE EVALUATE TRUE WHEN WS-RENT-APTNO = 1 AND WS-RENT-BUILDING = A PERFORM 100-RENT-REPORT WHEN WS-RENT-APTNO = 2 AND WS-RENT-BUILDING = A PERFORM 200-RENT-REPORT WHEN OTHER PERFORM 999-ERROR-REPORT END-EVALUATE.
Example 3: EVALUATE with THRU EVALUATE WS-RENT-APTNO WHEN 1 THRU 99 PERFORM 100-RENT-REPORT WHEN 101 THRU 999 PERFORM 200-RENT-REPORT WHEN OTHER PERFORM 999-ERROR-REPORT END-EVALUATE.
Example 4: EVALUATE with multiple WHEN conditions EVALUATE WS-RENT-APTNO WHEN 1 WHEN 2 WHEN 3 PERFORM 100-RENT-REPORT WHEN 4 WHEN 5 WHEN 6 PERFORM 200-RENT-REPORT WHEN OTHER PERFORM 999-ERROR-REPORT END-EVALUATE.
Example 5: EVALUATE with MULTIPLE conditions EVALUATE WS-RENT-APTNO ALSO TRUE WHEN 1 THRU 99 ALSO WS-RENT-BUILDING = "A" PERFORM 100-RENT-REPORT WHEN 101 THRU 999 ALSO WS-RENT-BUILDING = "A" PERFORM 200-RENT-REPORT WHEN OTHER PERFORM 999-ERROR-REPORT END-EVALUATE.
Example 6: EVALUATE with MULTIPLE conditions EVALUATE TRUE ALSO TRUE WHEN WS-RENT-APTNO <= 99 ALSO WS-RENT-BUILDING = "A" PERFORM 100-RENT-REPORT WHEN WS-RENT-APTNO > 99 ALSO WS-RENT-BUILDING = "A" PERFORM 200-RENT-REPORT WHEN OTHER PERFORM 999-ERROR-REPORT END-EVALUATE.
COBOL Blog: Click Here IBM Reference: Click Here
Optimize Outer Join queries is a powerful tool for retrieving data from multiple tables. However,…
OUTER JOIN Queries are a valuable tool in SQL, allowing you to retrieve data from…
Mastering impediments is crucial to the Scrum Master's role in fostering a high-performing Scrum Team.…
A Sprint Goal is a short, clear, and motivating target the Scrum Team aims to…
Context switching refers to changing focus or shifting attention from one task or activity to…
Embracing change is never easy, especially when it involves a shift in work methodology. Motivate…