Page 1 of 1

How to know the end of file??

PostPosted: Tue May 17, 2011 4:17 pm
by madhusudhanreddys
Hi All,

I facing an issue while reading a file. I have program which will read a file and write into another file. Issue is last record(only last record) in the input file is written twice into output file. If input file is having 2 records , my output is having 3 records.

below is my code :

READ IN210-INP-FILE
  AT END SET EOF-FOUND          TO TRUE
  NOT AT END SET NOT-EOF-FOUND TO TRUE
END-READ



When i checked with DISPALY statements, found that EOF flag (EOF-FOUND ) is set to true after reading the last record twice i.e if i/p file is one record , EOF flag is set only after reading 2 records (reading last record twice).

Example : i/p file is having only one record in the below example output)
Below is output from spool :

PROGRAM DTM00201 STARTS
CALLED PROCESS 0001 TIMES
WRITING TO UNQ FILE
CALLED PROCESS 0002 TIMES
WRITING TO UNQ FILE




Can anyone suggest what needs to done.

Thanks in advance

Re: How to know the end of file??

PostPosted: Tue May 17, 2011 5:14 pm
by Robert Sample
When i checked with DISPALY statements, found that EOF flag (EOF-FOUND ) is set to true after reading the last record twice i.e if i/p file is one record , EOF flag is set only after reading 2 records (reading last record twice).
I think you are misinterpreting what happens. COBOL reads the first record and returns it. EOF-FOUND will not be set. When COBOL attempts to read the second record, EOF-FOUND will be set and no record is returned since the end of the file is reached. End of file is never set if a record is returned -- only after the last record is read and another read attempt is made will the end of file condition apply.

Re: How to know the end of file??

PostPosted: Tue May 17, 2011 6:53 pm
by madhusudhanreddys
Thank you Robert. I have found the issue , there was small logical mistake in the code. Thank you for ur help