Friday, November 18, 2011

EVALUATE


With COBOL85, we use the EVALUATE verb to implement the case structure of other languages. Multiple IF statements can be efficiently and effectively replaced with EVALUATE statement. After the execution of one of the when clauses, the control is automatically come to the next statement after the END-EVALUATE. Any complex condition can be given in the WHEN clause. Break statement is not needed, as it is so in other languages.

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.

Sample

EVALUATE SQLCODE ALSO TRUE
WHEN 100 ALSO A=B imperative statement
WHEN  -305 ALSO (A/C=4) imperative statement
WHEN OTHER imperative statement
END-EVALUATE

No comments:

Post a Comment