Regarding End of file status



Support for OS/VS COBOL, VS COBOL II, COBOL for OS/390 & VM and Enterprise COBOL for z/OS

Regarding End of file status

Postby VIJAY1 » Thu Oct 25, 2012 4:42 pm

 PERFORM UNTIL WS-IN-STAT = 10  //HERE WS-IN-STAT IS STATUS OF FILE1         
 READ FILE1                               
 IF PROJ = 'MX' OR PROJ = 'BOA'           
 *WRITE record INTO 1ST FILE
 END-IF                                   
 IF PROJ = 'CITI' OR PROJ = 'USAA'         
 *WRITE record INTO 2ND FILE
 END-IF                                   
 DISPLAY 'ENTERED'                         
 IF PROJ = 'BENCH'                         
 *WRITE record INTO 3RD FILE
 END-IF                                 
 END-PERFORM.

whenever i implement this logic last record is getting copied twice..

Can some help me to resolve it.
Thank you.
VIJAY1
 
Posts: 26
Joined: Sun Oct 21, 2012 2:49 pm
Has thanked: 3 times
Been thanked: 0 time

Re: Regarding End of file status

 

Re: Regarding End of file status

Postby Pandora-Box » Thu Oct 25, 2012 4:47 pm

Is this related to any of the old topic?

Ensure if you have something like this

Open input
Open out1,out2,out3
Read Input
Perform until end of file
      Evaluate true
            when PROJ = 'MX' OR PROJ = 'BOA'           
                     write out1
            when PROJ = 'CITI' OR PROJ = 'USAA'     
                     write out2
            when PROJ = 'BENCH'
                     write out3
      End-Evaluate
      Read input
End-perform
Close input,iout1,out2,out3
Last edited by Pandora-Box on Thu Oct 25, 2012 4:53 pm, edited 1 time in total.
User avatar
Pandora-Box
 
Posts: 65
Joined: Fri Feb 10, 2012 8:30 pm
Location: Mars
Has thanked: 3 times
Been thanked: 6 times

Re: Regarding End of file status

Postby VIJAY1 » Thu Oct 25, 2012 4:52 pm

Yes but the doubt is new one.so i created another thread.I checked it several times.But i cannot understand why it is happening everytime.Can you please help?
VIJAY1
 
Posts: 26
Joined: Sun Oct 21, 2012 2:49 pm
Has thanked: 3 times
Been thanked: 0 time

Re: Regarding End of file status

Postby VIJAY1 » Thu Oct 25, 2012 4:56 pm

Thank you for your fast reply.:)
VIJAY1
 
Posts: 26
Joined: Sun Oct 21, 2012 2:49 pm
Has thanked: 3 times
Been thanked: 0 time

Re: Regarding End of file status

Postby Robert Sample » Thu Oct 25, 2012 6:06 pm

When the READ is done as the first line of the PERFORM loop, end-of-file is set. However, a PERFORM loop does not break on the condition -- rather, the condition is tested either before the loop begins or after the loop finishes. So the statements after the READ in the PERFORM loop are executed, and since the data did not change due to hitting end of file there's no new data to process and the last record gets processed a second time. When the end of the PERFORM loop is reached, THEN the program detects end of file and terminates the PERFORM loop.

When we told you to read the first record, then set up your PERFORM so the last thing it does is another READ, we had a reason for saying this -- we don't just arbitrarily tell you things. YOU may not know the reason some things get said, but we always have a reason for saying what we say.

These users thanked the author Robert Sample for the post (total 2):
VIJAY1 (Fri Oct 26, 2012 12:28 am) • Pandora-Box (Thu Oct 25, 2012 6:35 pm)
Robert Sample
Global moderator
 
Posts: 3367
Joined: Sat Dec 19, 2009 8:32 pm
Location: East Dubuque, Illinois
Has thanked: 1 time
Been thanked: 222 times

Re: Regarding End of file status

Postby VIJAY1 » Fri Oct 26, 2012 12:28 am

Thanks Robert.you made it extremely clear.
VIJAY1
 
Posts: 26
Joined: Sun Oct 21, 2012 2:49 pm
Has thanked: 3 times
Been thanked: 0 time

Re: Regarding End of file status

Postby dick scherrer » Fri Oct 26, 2012 2:59 am

Hello,

YOU may not know the reason some things get said, but we always have a reason for saying what we say.
To paraphrase what one of our best uses as a byline:

"We can explain it to you, but we cannot understand it for you".

When one of the seniors provides direction, it would be a very good practice to make sure it is not only usable, but understood. When there are further doubts - ask, someone will be able to help clarify.
Hope this helps,
d.sch.
User avatar
dick scherrer
Global moderator
 
Posts: 6304
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 91 times


Return to IBM Cobol

 


  • Related topics
    Replies
    Views
    Last post