Sunday 28 April 2019

COBOL Evaluate Statement | Different Forms Of Evaluate Statement In COBOL [COBOL Evaluate Example].


EVALUATE in COBOL, Evaluate in cobol, evaluate cobol example

Different forms of COBOL Evaluate Statement


Welcome back to today's session on "COBOL Evaluate Statement". In this session, we will precisely explain the "Evaluate Statement in COBOL" and deep dive into the different forms of COBOL Evaluate statements. You'll go through different Evaluate statement examples for better understanding. So, let's get started with an introduction to COBOL Evaluate Statement. 

COBOL Evaluate Statement - Agenda. 

  • Introduction to Evaluate Statement in COBOL. 
  • How and when to use Evaluate in COBOL.
  • Different forms of COBOL Evaluate Statement.
  • COBOL Evaluate Statement Example. 
  • COBOL Evaluate Statement Tutorial.
  • Conclusion. 

Introduction.

EVALUATE in COBOL is similar to Microsoft Visual Basic "Select Case Statement". COBOL Evaluate statement is easy to implement and improve code readability. The key difference between EVALUATE and VBA Select Case is that no ‘Break’ is required i.e. control automatically transpire of the EVALUATE statement as soon as condition matched.

You can use Nested Evaluate in COBOL instead of nested If-ELSE statements.

How and when to use the COBOL Evaluate statement?

COBOL EVALUATE clause is better than nested IF-ELSE statement in terms of performance it saves a lot of CPU and simplifies the program logic. You can use nested IFs statements to implement business logic. There is no end to the depth of COBOL nested IF statements. But, when the COBOL program has to examine a variable for more than two levels, EVALUATE is the more preferred choice. 

Evaluate statement in COBOL is faster than nested IF-ELSE statements. It is not possible to replace all nested-Ifs in the program but you should try to replace as much as you can. 

Evaluate in COBOL Syntax. 

Let me write down the syntax of the COBOL EVALUATE statement.

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

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

During the execution of a COBOL EVALUATE statement, the values denoted by the list of subjects (items in the EVALUATE statement in COBOL) are compared with the values denoted by the list of objects in a WHEN phrase to establish a “match” between the two.

The value of a subject is compared with the value/range of values of the object in the corresponding ordinal position In the case of a single-valued (numeric/non-numeric) object, the subject-object comparison is done in the usual way.

When a range of values is specified for the object, the subject-object comparison results in TRUE, if the value of the subject falls within the range In the case of conditional values, the subject-object comparison results in TRUE, if both evaluate to the same value (that is if both are TRUE or both are FALSE).


Different forms of COBOL Evaluate Statement.

COBOL Evaluate statement has multiple formats. These formats suit the need of the programmer and enable them to implement business logic seamlessly. Let's deep dive into different forms of COBOL Evaluate Statements. 

#1. COBOL EVALUATE WHEN TRUE.

In this example, you'll see how to use multiple when conditions (i.e. COBOL evaluate multiple when). 

EVALUATE TRUE 
   WHEN END-OF-THE-FILE 
        PERFORM A00-WRT-TRL-REC 
   WHEN NOT-END-OF-THE-FILE 
        PERFORM B00-WRT-DTL-REC 
        PERFORM B10-RED-NXT-REC 
   WHEN OTHER 
        PERFORM Z00-CLL-ERR End-EVALUATE 
END-EVALUATE.


#2. COBOL EVALUATE WHEN TRUE ALSO TRUE.

The following example explains how you can code COBOL EVALUATE WHEN TRUE ALSO TRUE conditions (i.e. COBOL evaluate condition). 

EVALUATE TRUE ALSO TRUE
   WHEN WS-A = WS-B ALSO WS-C = WS-D
        DISPLAY 'CASE 1 is True' 
   WHEN WS-A > WS-B ALSO WS-C < WS-D 
        DISPLAY 'CASE 2 is True'  
   WHEN OTHER 
        DISPLAY 'OTHER CASE is True' 
END-EVALUATE.

#3. COBOL FORMAT 3: EVALUATE .... WHEN with multiple conditions i.e. AND and OR operator.

The following example explains how you can code COBOL EVALUATE WHEN with multiple conditions with logical operators (i.e. COBOL evaluate condition).

EVALUATE MARTIAL-STATUS 
   WHEN 'M'
        DISPLAY 'Married' 
   WHEN 'S'
   WHEN 'D'
   WHEN 'W'  
        DISPLAY 'Single'  
   WHEN OTHER 
        DISPLAY 'Not Specified' 
END-EVALUATE.


EVALUATE TRUE 
   WHEN WS-AGE > 10 AND WS-GEN = 'M'
        DISPLAY 'MALE with Age > 10' 
   WHEN WS-AGE > 10 AND WS-GEN = 'F' 
        DISPLAY 'Female with Age > 10'  
   WHEN (WS-AGE > 10 OR WS-AGE < 15) AND WS-GEN = 'F' 
        DISPLAY 'Female with Age between 10 - 15'  
   WHEN OTHER 
        DISPLAY 'Criteria not satisfy' 
END-EVALUATE.


#4 COBOL EVALUATE using THRU Phrase (i.e. EVALUATE WHEN with THRU).

This example teaches how you can code different conditions in a series of values to lead to the corresponding processing action by coding the THRU phrase. Operands in a COBOL EVALUATE THRU phrase must be of the same class.


EVALUATE WS-NUMBER
    WHEN 1
         DISPLAY '1'
    WHEN 2 
         DISPLAY '2' 
    WHEN 3 THRU 6
         DISPLAY 'Number between 3 - 6'
    WHEN OTHER 
         DISPLAY 'NUMBER not in range' 
END-EVALUATE.

If ANY is specified for an object, the subject-object comparison always results in TRUE 
The list of subjects is said to “match” with the list of the object if all the corresponding subject-object comparisons result in true 

Note: that the values of the subjects need not be of the same class. For example, one can be numeric and the other can be alphanumeric After the execution of one of the when clauses, the control is automatically passed on to the next sentence after the EVALUATE statement

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™

1 comment:

  1. Nice article, infact author has explain the different form Evaluate precisely.

    Thanks.

    ReplyDelete

New In-feed ads