Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums 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: 8201
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: 7314

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
This topic is locked: you cannot edit posts or make replies. Cobol to fetch the content by using s... arunc55 COBOL Programming 4 Fri Nov 17, 2017 1:25 pm
No new posts VBS and VB, COBOL syntax is the same ... natt.sut COBOL Programming 3 Sun Nov 12, 2017 6:36 am
No new posts COBOL - EXIT statement weird behavior anthony.pangestu COBOL Programming 0 Fri Oct 27, 2017 9:57 am
No new posts IEW2456E error when link-editing a C ... Senthilraj JCL & VSAM 0 Fri Oct 13, 2017 3:12 pm
No new posts Assembler Macro Copybook converted to... Ziquilix PL/I & Assembler 4 Tue Sep 26, 2017 3:07 am

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