Saturday, 30 August 2014

COBOL Evaluate Statement | EVALUATE statement in COBOL.

Evaluate statement
COBOL Evaluate statement.

COBOL Evaluate statement is similar to SWITCH, CASE statement of any other programming language for example VB 6.0 macro programming language. In this Evaluate in COBOL Tutorial, I would explain the usage of COBOL EVALUATE statement with syntax and example.

Evaluate statement in COBOL is used to implement the case structure. It tests for series of values. 
The Evaluate statement became available with COBOL-85. It has a complicated syntax that lets you use this statement for a variety of purposes. No matter how you code it, though, it always has one entry point and one exit point, so it is a valid structure for structured programming.

COBOL EVALUATE is better than Nested-ifs in terms of performance and it improves the readability of COBOL program. COBOL Evaluate statement can be used in different forms for example: Evaluate True in COBOL, Evaluate Thru in COBOL, Evaluate WHEN in COBOL etc.
Format : 
COBOL Evaluate
COBOL evaluate statement Syntax

Each time an Evaluate statement is executed, the conditions in the When clauses are tested in sequence, starting with the first When clause. When a condition in a When clause is true, the statements in that clause are executed and the Evaluate statement ends without evaluating the other conditions.

Example 1:
   WHEN A=B AND C=D             WHEN 100 ALSO ‘00’
        imperative stmt              imperative stmt
   WHEN (D+X)/Y = 4             WHEN -305 ALSO ‘32’
        imperative stmt              imperative stmt
   WHEN OTHER                   WHEN OTHER
        imperative stmt              imperative stmt

Example 2:
Cobol evaluate
COBOL Evaluate statement Example
The Evaluate statement can be used to implement a case structure for one or more fields. When you work with more than one field, you use the word ALSO before each additional field. Then, in the When clauses, you use the word ALSO before each additional value.

COBOL Evaluate Statement.

No comments:

Post a comment