Saturday 30 August 2014

COBOL Evaluate Statement | EVALUATE statement in COBOL [COBOL Evaluate Examples].


Evaluate statement

COBOL Evaluate statement.


Welcome back to today's session on "COBOL Evaluate Statement". In this session, you'll learn the basics of Evaluate statement in COBOL. Also, you'll go through a couple of examples to re-enforce your COBOL Evaluate knowledge. Let's get started with an introduction to COBOL Evaluate Statement. 

COBOL Evaluate Statement - Agenda. 

  • Introduction to COBOL Evaluate Statement.
  • COBOL Evaluate Statement Syntax.
  • COBOL Evaluate Example. 
  • Different Forms Of Evaluate Statement.
  • Evaluate in COBOL - Youtube.
  • Conclusion.

Introduction to 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 the 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 the 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.

COBOL Evaluate Statement Syntax.  

Evaluate statement in COBOL is pretty simple and easy to understand. In fact, the COBOL Evaluate statement is more flexible as compare to the COBOL Ifs statement. Here is the simple format of COBOL Evaluate Syntax.

* The syntax of the Evaluate statement as an If-statement alternative.

EVALUATE TRUE
    WHEN Condition-1
         Statement ... 
    WHEN OTHER 
         Statement- ... 
END-EVALUATE. 

 
Evaluate statement in COBOL, 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.

#1 COBOL Evaluate Statement Example.

The following COBOL Evaluate statement example reveals how you can code multiple conditions by using the when clause in the COBOL Evaluate statement (i.e. COBOL evaluate true).  
                                                         
EVALUATE                     EVALUATE SQLCODE ALSO FILE-STATUS
   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
END-EVALUATE                 END-EVALUATE 

#2 COBOL Evaluate Statement Example.




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.

Different Forms Of Evaluate Statement.

The COBOL Evaluate Statement has formats to suits the need of programmers. You can use the EVALUATE statement in COBOL to combine multiple conditions instead of nested ifs. Following are the different types of COBOL Evaluate.

  • COBOL Evaluate WHEN TRUE.
  • COBOL Evaluate WHEN TRUE ALSO TRUE.
  • COBOL Evaluate using Thru phrase.
  • COBOL Evaluate using multiple WHEN.
Do check out the "Different Forms Of Evaluate Statement In COBOL" post for a detailed explanation of COBOL Evaluate Statement types

COBOL EVALUATE Statement - Youtube.



Conclusion. 

Finally, this marks an end to the COBOL Evaluate Statement. COBOL Evaluate statement goes hand in hand and you got an alternative to COBOL Ifs statements. Evaluate statement in COBOL is better than IFs statement in terms of performance. Do check out COBOL LEVEL 88 Condition.


Subscribe to Topictrick & Don't forget to press THE BELL ICON to never miss any updates. Also, Please visit mention the link below to stay connected with Topictrick and the Mainframe forum on - 

► Youtube
► Facebook 
► Reddit

Thank you for your support. 
Mainframe Forum™
Share COBOL
COBOL Evaluate Statement.

No comments:

Post a Comment

New In-feed ads