IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

why last record is writing twice in the output file


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
suneelv

New User


Joined: 26 Aug 2008
Posts: 52
Location: inida

PostPosted: Fri Jan 23, 2009 6:52 pm
Reply with quote

Hi,

I am reading sequential file and doing some operations and writing records into output file till the end of the file, but the last record in the input file is writing twice in the o/p file.

Could any one help in this.

Regards
Suneel
Back to top
View user's profile Send private message
superk

Global Moderator


Joined: 26 Apr 2004
Posts: 4652
Location: Raleigh, NC, USA

PostPosted: Fri Jan 23, 2009 6:57 pm
Reply with quote

Logic error.
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Sat Jan 24, 2009 2:06 am
Reply with quote

Hello,

Does the code use "write. . . from " some working-storage field?

Is yes, possibly due to the code issuing a write/from after end-of-file is detected - the last data in the ws area would be written again. . .
Back to top
View user's profile Send private message
rajulan

New User


Joined: 11 Jan 2008
Posts: 66
Location: India

PostPosted: Tue Jan 27, 2009 10:06 am
Reply with quote

Have you issued " STOP RUN" ?

Thanks,
Rajulan.
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Tue Jan 27, 2009 10:20 am
Reply with quote

Hello,

How does "STOP RUN" cause or prevent an extra write of the last record?
Back to top
View user's profile Send private message
rajulan

New User


Joined: 11 Jan 2008
Posts: 66
Location: India

PostPosted: Tue Jan 27, 2009 1:35 pm
Reply with quote

dick

Some times If you dont specify STOP RUN in your program the behaviour might be unpredictable. Most probably your program will not end execution and an out of time error (S322) will be thrown...or if u display the records in the spool, you can see the last records or other records repeated many times. Here the case is it is repeated twice. It may or may not be the cause. I just asked him to check out whether he has coded STOP RUN.

suneelv if u post some code , someone may be able to help to fix this one.

Thanks,
Rajulan.

[/b]
Back to top
View user's profile Send private message
aryanpa1

New User


Joined: 26 May 2007
Posts: 45
Location: Chennai

PostPosted: Tue Jan 27, 2009 2:23 pm
Reply with quote

Hi ,

Try to put the the "WRITE" statement inside if condition "If NOT-END-OF-FILE"
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Tue Jan 27, 2009 2:30 pm
Reply with quote

Hello,

Quote:
Most probably your program will not end execution and an out of time error (S322) will be thrown...
Very, very seldom will a missing STOP RUN cause an s322. Why would you believe this?

An s322 as you describe (as well as repeated display of the same info) is most often caused by the program going into some loop (because a goback or stop run was not executed). The goback or stop run might be coded, but the logic error causes the code to never reach the termination code.

As this question involves only 1 extra record and no abend was mentioned the problem will be as Kevin and i mentioned before - a logic error.
Back to top
View user's profile Send private message
rajulan

New User


Joined: 11 Jan 2008
Posts: 66
Location: India

PostPosted: Tue Jan 27, 2009 3:49 pm
Reply with quote

Yes dick i agree with you. I have come across this logic error before. At first i had due to Stop Run missing infinite loop. Thats what i asked him to check out.

I fully agree ur suggestion.

If i had mainframe express handy, i would have done some small test and posted the solution.

The logic error is this paragraph. The MOVE and WRITE statements are executed even when the READ statement detects that there are no more input records. The routine should be coded:

200-PROCESS-RTN.
READ IN-FILE
AT END
MOVE ’NO ’ TO ARE-THERE-MORE-RECORDS
NOT AT END
MOVE IN-RECORD TO OUT-RECORD
WRITE OUT-RECORD
END-READ.

Thanks,
Rajulan.
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Wed Jan 28, 2009 1:47 am
Reply with quote

Hello,

Yes, that could work if the code was so written. There are many, many other ways to properly write the code so i expect that the way the code is currently structured would need to be considered.

If Suneel provides some additonal info, we may be better able to help. . .
Back to top
View user's profile Send private message
Shashank.kapoor

New User


Joined: 14 Jan 2009
Posts: 24
Location: Mumbai

PostPosted: Wed Jan 28, 2009 2:41 pm
Reply with quote

Hi Suneel,

Along with the read statement please provide us the loop condition as well.

While writting in an output file, your loop is executing twice for last record i.e. you are writting the last record even when the pointer is on end of file.
Check the position where you are setting your flag to end the loop.

Thanks & Regards,
Shashank Kapoor
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Compare 2 files and retrive records f... DFSORT/ICETOOL 3
No new posts TRIM everything from input, output co... DFSORT/ICETOOL 1
No new posts FTP VB File from Mainframe retaining ... JCL & VSAM 8
No new posts Extract the file name from another fi... DFSORT/ICETOOL 6
No new posts How to split large record length file... DFSORT/ICETOOL 10
Search our Forums:

Back to Top