Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Forum Index
 
Register
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Profile Log in to check your private messages Log in
 
AT END and NOT AT END in COBOL

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
Agni

New User


Joined: 22 Nov 2007
Posts: 83
Location: Chennai

PostPosted: Sun May 19, 2013 3:35 pm    Post subject: AT END and NOT AT END in COBOL
Reply with quote

Dear All,

I am working on a requirement in which I have to create a new copy book and have to move the file operations like Open, Read, Write, close etc. for four different programs. I have a code as mentioned below from which I have to take the Read part alone (first four lines) and move it to the copy book. It is in the paragraph READ-FILE in the program. This paragraph is called 4 times in the program.




Code:


READ-FILE.
     READ <File name>
         NEXT
         AT END
           MOVE 2 TO <File-Status>
         NOT AT END
           IF A = 2 OR 3
              Do Something
           ELSE
              Do Something else
           END-IF.


I split the code into two parts as below. Moved the below Read part to the copy book and added an IF condition to check the for the 'not end of file' status as below.

(Below READ statement is moved to copybook with a paragraph name)

Code:

READ-FILE.
     READ <File name>
         NEXT
         AT END
           MOVE 2 TO <File-Status>.


Below code snippet is retained in the program itself and is added after where the original READ-FILE is called.

Code:

        IF File-status NOT = 2
           IF A = 2 OR 3
              Do Something
           ELSE
              Do Something else
           END-IF
        END-IF.


Here I am facing a problem wherein there is a PERFORM READ-FILE UNTIL END-OF-FILE OR VALID-NAME in the ELSE part of an IF condition.
If I add the second part of split code after the above PERFORM paragraph, I feel that the IF condition I added may not be executed
because of the END-OF-FILE switch is set. Please note that the File-status here is nothing but the END-OF-FILE.



Code:


   ELSE
          PERFORM READ-FILE
             UNTIL END-OF-FILE
                OR VALID-NAME
             IF File-status NOT = 2
                IF A = 2 OR 3
                   Do Something
                ELSE
                   Do Something else
                END-IF
             END-IF.


Is there any way that I can get rid of this? I hope I have explained properly. Pls let me know if you have any queries.

Cheers
Agni.
Back to top
View user's profile Send private message

Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8491
Location: Dubuque, Iowa, USA

PostPosted: Sun May 19, 2013 7:33 pm    Post subject:
Reply with quote

By using a copy book in the way you are using it, you are changing the logic. In the original code you posted, PERFORM READ-FILE UNTIL END-OF-FILE will test A to be 2 or 3 and perform appropriate code each time a record is read. Your revised logic will test A to be 2 or 3 only after the end of file is reached (or VALID-FILE is set, whatever that is), not for each record.

What you want to do can be done, but you will have to rewrite the logic of the program to properly separate open / read / write / close logic from the business logic. Such a rewrite may require anything from changing a few statements to a complete rewrite of the code depending upon the logic. You need to go to whoever gave you the task, explain the problem, and find out if you should attempt to rewrite the code or accept that using a copy book for file operations in that program will not work.
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7312

PostPosted: Mon May 20, 2013 1:24 am    Post subject: Reply to: Pls help: AT END and NOT AT END in COBOL
Reply with quote

Priming read.
Code:

PERFORM READ
PERFORM UNTIL END-OF-FILE (10 on FILE-STATUS field)
    Do some stuff
    PEFORM READ
END-PERFORM


Gets all the "file" processing (including headers and trailers, empty files) away from the business logic. Just keep all of the stuff away from "Do some stuff".
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts How to handle NULL in COBOL program bhaskar_kanteti COBOL Programming 8 Mon Oct 07, 2019 3:54 pm
This topic is locked: you cannot edit posts or make replies. COBOL/CICS with real time MQ Series u... BPranav CICS 2 Mon Sep 16, 2019 9:19 pm
This topic is locked: you cannot edit posts or make replies. Compare two files logic in COBOL Nishant Singhal COBOL Programming 4 Sun Aug 25, 2019 2:25 am
This topic is locked: you cannot edit posts or make replies. Upgrade to Enterprise COBOL 6 JPVRoff COBOL Programming 4 Thu Aug 01, 2019 7:21 am
No new posts COBOL copybook to Focus anandgbe COBOL Programming 7 Wed Jul 31, 2019 11:52 am

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us