How to know the end of file??



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

How to know the end of file??

Postby madhusudhanreddys » Tue May 17, 2011 4:17 pm

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
madhusudhanreddys
 
Posts: 3
Joined: Fri Apr 08, 2011 4:10 pm
Has thanked: 0 time
Been thanked: 0 time

Re: How to know the end of file??

 

Re: How to know the end of file??

Postby Robert Sample » Tue May 17, 2011 5:14 pm

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.
Robert Sample
Global moderator
 
Posts: 3367
Joined: Sat Dec 19, 2009 8:32 pm
Location: Dubuque, Iowa, USA
Has thanked: 1 time
Been thanked: 222 times

Re: How to know the end of file??

Postby madhusudhanreddys » Tue May 17, 2011 6:53 pm

Thank you Robert. I have found the issue , there was small logical mistake in the code. Thank you for ur help
madhusudhanreddys
 
Posts: 3
Joined: Fri Apr 08, 2011 4:10 pm
Has thanked: 0 time
Been thanked: 0 time


Return to IBM Cobol

 


  • Related topics
    Replies
    Views
    Last post