Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

why last record is writing twice in the output file

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
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    Post subject: why last record is writing twice in the output file
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

Moderator Team Head


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

PostPosted: Fri Jan 23, 2009 6:57 pm    Post subject: Reply to: why last record is writing twice in the output fil
Reply with quote

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

Site Director


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

PostPosted: Sat Jan 24, 2009 2:06 am    Post subject:
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    Post subject:
Reply with quote

Have you issued " STOP RUN" ?

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

Site Director


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

PostPosted: Tue Jan 27, 2009 10:20 am    Post subject:
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    Post subject:
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    Post subject:
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

Site Director


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

PostPosted: Tue Jan 27, 2009 2:30 pm    Post subject:
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    Post subject:
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

Site Director


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

PostPosted: Wed Jan 28, 2009 1:47 am    Post subject:
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    Post subject: Reply to: why last record is writing twice in the output fil
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    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Converting Variable block file to Fix... bhavana yalavarthi DFSORT/ICETOOL 10 Tue May 16, 2017 2:20 pm
No new posts find RACF group for access to spooled... jzhardy JCL & VSAM 1 Mon May 08, 2017 11:46 am
No new posts Adding big TEXT lines to each record ... bshkris SYNCSORT 4 Sat May 06, 2017 1:40 am
No new posts Getting error while opening a variabl... apandey1 COBOL Programming 5 Fri May 05, 2017 12:22 pm
This topic is locked: you cannot edit posts or make replies. Merge two files and update Trailer re... Yashashri JCL & VSAM 1 Thu May 04, 2017 12:54 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us