Home      Mainframe Forum      Mainfarme Tutorials      IBM Manuals      Mainframe Interview Questions      Mainframe Books      IT News     SiteMap     Downloads


     
 
MAINFRAME - TIP OF THE DAY : All available storage is assigned to the job or jobstep, If REGION is coded 0K or 0M

Google
 
Web mainframegurukul.com

EVALUATE

 
Post new topic   Reply to topic    mainframegurukul.com Forum Index -> COBOL
  View previous topic :: View next topic  
Author Message
Sandrit
Member


Joined: 11 Sep 2015
Posts: 6

Answer was approved by Question owner.
Useful Post
0 votes
Not an useful post
Greate Post!! Salute Author
0 salutes

PostPosted: Sun Sep 20, 2015 5:55 am    Post subject: EVALUATE Reply with quote

Code:
*READ THE N36-RECORD.

      MOVE N23-KEY-ID      TO N5-KEY1-ID.     
      M0VE 10       TO R2-READ.
      PERFORM K100-READ.

*UPDATE THE N-36-RECORD.
       IF N2-STOP = 'Y'
              MOVE 'A'                                TO N36-STATE
              GO TO C100
        END-IF.

        IF N38-HOLD  = 'Y'
              MOVE 'B'                    TO N36-STATE
              IF N36-AMOUNT > N38-AMOUNT
                 MOVE 'A'                 TO N36-STATE
              ELSE
                 IF N38-DONE = 'Y'
                    MOVE 'C'              TO N36-STATE
                 END-IF
              END-IF
           END-IF.
C100.
           MOVE 5                         TO N2-REWRITE
           PERFORM H000-REWRITE.
       
          EXIT.


Hello,

I am trying to learn COBOL by myself. Can someone please explain to me how you can write this code using EVALUAE and without using GO TO. Thanks
Back to top
View user's profile Send private message
Click here, If this post answer your question. <-- Click on right mark icon. If this post answer your question.

William Collins
Active Member


Joined: 24 May 2012
Posts: 714

Answer was approved by Question owner.
Useful Post
0 votes
Not an useful post
Greate Post!! Salute Author
0 salutes

PostPosted: Sun Sep 20, 2015 1:39 pm    Post subject: Reply with quote

Code:
*READ THE N36-RECORD.

    MOVE N23-KEY-ID            TO N5-KEY1-ID.     
    M0VE 10                    TO R2-READ.
    PERFORM                    K100-READ.

*UPDATE THE N-36-RECORD.
    IF N2-STOP = 'Y'
        MOVE 'A'               TO N36-STATE
        GO TO C100
    END-IF.

    IF N38-HOLD  = 'Y'
        MOVE 'B'               TO N36-STATE
        IF N36-AMOUNT > N38-AMOUNT
            MOVE 'A'           TO N36-STATE
        ELSE
            IF N38-DONE = 'Y'
                MOVE 'C'       TO N36-STATE
            END-IF
        END-IF
    END-IF.
C100.
    MOVE 5                     TO N2-REWRITE
    PERFORM                    H000-REWRITE.
       
    EXIT.


Then you remove all full-stops/periods on lines of code, and end a paragraph/SECTION/program with a single full-stop/period in column 12 of an otherwise blank line.

If you are teaching yourself COBOL, be aware to avoid using GO TO like the utter, utter, plague. You may find this difficult at first, so don't stress about it. Just each time consider how to do it, more clearly, without the GO TO. It'll come. Or not.

EVALUATE is equivalent to a "nested-IF". You have a nested IF, but there is also an IF with a GO TO prior to that, which could have been included in the nested-IF, but wasn't. That can go into the EVALUATE as well:

Code:
*UPDATE THE N-36-RECORD.
    EVALUATE TRUE
        WHEN N2-STOP = 'Y'
            MOVE 'A'           TO N36-STATE
        WHEN N38-HOLD  = 'Y'
            MOVE 'B'           TO N36-STATE
        WHEN N36-AMOUNT > N38-AMOUNT
            MOVE 'A'           TO N36-STATE
        WHEN N38-DONE = 'Y'
            MOVE 'C'           TO N36-STATE
    END-EVALUATE


You have a lot of literals there. For someone to understand the program (say they're looking for a bug, or evaluating a change) then they have to know what Y (on different fields), A, B, and C mean.

If you used condition-names, COBOL's level-88, things become clearer to the reader:

Code:
    EVALUATE TRUE
        WHEN N2-STOPPED
            SET N36-STATE-ABANDONED
                               TO  TRUE
        WHEN N38-ON-HOLD
            SET N36-STATE-BLOKED
                               TO  TRUE
        WHEN N36-AMOUNT > N38-AMOUNT
            SET N36-STATE-ABANDONED
                               TO  TRUE
        WHEN N38-COMPLETE
            SET N36-STATE-COMPLETED
                               TO  TRUE
    END-EVALUATE


The entire fragment is now like this, shorter and much clearer:

Code:
*READ THE N36-RECORD.

    MOVE N23-KEY-ID            TO N5-KEY1-ID     
    M0VE 10                    TO R2-READ
    PERFORM                    K100-READ

    EVALUATE TRUE
        WHEN N2-STOPPED
            SET N36-STATE-ABANDONED
                               TO  TRUE
        WHEN N38-ON-HOLD
            SET N36-STATE-BLOKED
                               TO  TRUE
        WHEN N36-AMOUNT > N38-AMOUNT
            SET N36-STATE-ABANDONED
                               TO  TRUE
        WHEN N38-COMPLETE
            SET N36-STATE-COMPLETED
                               TO  TRUE
    END-EVALUATE

    MOVE 5                     TO N2-REWRITE
    PERFORM                    H000-REWRITE
    .


As well as being more literals, the 10 for read and five for rewrite seem unnecessary if you are going to PERFORM paragraphs of those names.
Back to top
View user's profile Send private message
Click here, If this post answer your question. <-- Click on right mark icon. If this post answer your question.
Sandrit
Member


Joined: 11 Sep 2015
Posts: 6

Answer was approved by Question owner.
Useful Post
0 votes
Not an useful post
Greate Post!! Salute Author
0 salutes

PostPosted: Sun Sep 20, 2015 5:42 pm    Post subject: Reply with quote

I could not understand how to use EVALUATE. But now after having seen your answer and explanations, I see it more clearly.
Your code is clean and easy to read, you make it look so easy.
Thanks so much for your help.
Back to top
View user's profile Send private message
Click here, If this post answer your question. <-- Click on right mark icon. If this post answer your question.
Display posts from previous:   
Post new topic   Reply to topic    mainframegurukul.com Forum Index -> COBOL All times are GMT + 5 Hours
Page 1 of 1



 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

Related topics
 Topics   Replies   Author   Views   Last Post 
No new posts Someone please explain this COMPUTE statement 3 Gurugars 1331 Fri May 01, 2015 2:27 pm
William Collins View latest post
No new posts can someone please provide me with a DB2 ppt for cobol 1 ashadwivedi24 1776 Fri Mar 30, 2012 2:48 pm
Anuj Dhawan View latest post
No new posts Coulu someone explain the parameters in the below code? 1 lovely sweety 11352 Thu Jun 09, 2011 3:50 pm
dbzTHEdinosauer View latest post
No new posts What does a career in IT look like today for someone new? 2 MrSpock 3243 Tue Jun 29, 2010 1:40 pm
Anuj Dhawan View latest post
No new posts Please someone explain the concepts of certifications 5 MrSpock 5655 Fri Mar 19, 2010 1:57 pm
Anuj Dhawan View latest post
 


Cobol Tutorial
This cobol tutorial covers most of the important topics like STRING, UNSTRING, COMP, COMP-3.....
DB2 Tutorial
DB2 Tutorial focuses on DB2 COBOL Programming. Explains in simple language. Some Chapters are locked, Forum members have free access to these chapters
CICS Tutorial
This CICS tutorial covers CICS concepts and CICS Basics, CICS COBOL Programming...
JCL Tutorial
This is most popular JCL tutorial from mainframegurukul. It does contain important jcl ....
SORT Tutorial
This Tutorial covers all important aspects of DFSORT. Has more SORT examples
INTERVIEW Questions
This page covers important interview questions
Mainframe Jobs
Mainframe Jobs posted by members of mainframegurukul forum
FaceBook Page
MainframeGurukul FaceBook Page
LinkedIn Page
MainframeGurkul Linkedin Page

This widget requires Flash Player 9 or better







Go to top of the page
 

Online ABEND Reference ||  JCL References ||  COBOL References ||  VSAM References ||  Tutorials by Drona Series ||  SQL tutorial ||  BOOKS  ||  DB2 INTERVIEW QUESTIONS ||  COBOL INTERVIEW QUESTIONS  ||  JCL INTERVIEW QUESTIONS ||  JCL2 INTERVIEW QUESTIONS ||  VSAM INTERVIEW QUESTIONS ||  CICS INTERVIEW QUESTIONS  ||  Online tutorials ||  Online ABEND Reference ||  JCL References ||  COBOL References ||  VSAM References ||  Tutorials by Drona Series ||  SQL tutorial ||  BOOKS  ||  SiteMap  ||  Expeditor Tutorial  ||  FILE-AID Tutorial  ||  Changeman Tutorial  ||  COBOL   ||  DB2   ||  JCL  ||  CICS  ||  VSAM  ||  DB2 Interview Questions ( 110 )   || Simple JCL Tutorials  || JCL Tutorial from MainframeGurukul.com   || Simple JCL Tutorial - Chapter1 ;|| Mainframe Forum - Tutorials  || Mainframe Tutorials || Mainframe CICS tutorial|| Mainframe COBOL Tutorial

Drona Educational Forums - Mainframe Cobol DB2 CICS Board
Powered by phpBB

mainframetopic-7935.html