Page 1 of 1

Regarding End of file status

PostPosted: Thu Oct 25, 2012 4:42 pm
by VIJAY1
 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.

Re: Regarding End of file status

PostPosted: Thu Oct 25, 2012 4:47 pm
by Pandora-Box
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

Re: Regarding End of file status

PostPosted: Thu Oct 25, 2012 4:52 pm
by VIJAY1
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?

Re: Regarding End of file status

PostPosted: Thu Oct 25, 2012 4:56 pm
by VIJAY1
Thank you for your fast reply.:)

Re: Regarding End of file status

PostPosted: Thu Oct 25, 2012 6:06 pm
by Robert Sample
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.

Re: Regarding End of file status

PostPosted: Fri Oct 26, 2012 12:28 am
by VIJAY1
Thanks Robert.you made it extremely clear.

Re: Regarding End of file status

PostPosted: Fri Oct 26, 2012 2:59 am
by dick scherrer
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.