View previous topic :: View next topic
|
Author |
Message |
suneelv
New User
Joined: 26 Aug 2008 Posts: 52 Location: inida
|
|
|
|
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 |
|
|
superk
Global Moderator
Joined: 26 Apr 2004 Posts: 4652 Location: Raleigh, NC, USA
|
|
|
|
Logic error. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
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 |
|
|
rajulan
New User
Joined: 11 Jan 2008 Posts: 66 Location: India
|
|
|
|
Have you issued " STOP RUN" ?
Thanks,
Rajulan. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
How does "STOP RUN" cause or prevent an extra write of the last record? |
|
Back to top |
|
|
rajulan
New User
Joined: 11 Jan 2008 Posts: 66 Location: India
|
|
|
|
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 |
|
|
aryanpa1
New User
Joined: 26 May 2007 Posts: 45 Location: Chennai
|
|
|
|
Hi ,
Try to put the the "WRITE" statement inside if condition "If NOT-END-OF-FILE" |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
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 |
|
|
rajulan
New User
Joined: 11 Jan 2008 Posts: 66 Location: India
|
|
|
|
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 |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
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 |
|
|
Shashank.kapoor
New User
Joined: 14 Jan 2009 Posts: 24 Location: Mumbai
|
|
|
|
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 |
|
|
|