View previous topic :: View next topic
|
Author |
Message |
premkumar82
New User
Joined: 24 Feb 2006 Posts: 8 Location: chennai
|
|
|
|
I am a reading a file and after doing some validations i am writing the records into o/p file. In my case the last record of my ip file is written 2 time in the op file. I checked the 'At END' phrases in my code, they look correct. could anyone help me. |
|
Back to top |
|
|
h.dinesh
New User
Joined: 06 Dec 2006 Posts: 46 Location: Chennai
|
|
|
|
premkumar,
Please paste the code so that all can check it.
Dinesh |
|
Back to top |
|
|
William Thompson
Global Moderator
Joined: 18 Nov 2006 Posts: 3156 Location: Tucson AZ
|
|
|
|
premkumar82 wrote: |
I am a reading a file and after doing some validations i am writing the records into o/p file. In my case the last record of my ip file is written 2 time in the op file. I checked the 'At END' phrases in my code, they look correct. could anyone help me. |
Me thinks, though "they look correct", something isn't.... It might be something as simple as a missing/extra period or a performed paragraph accidentally fallen through or a test before thought to be after..... |
|
Back to top |
|
|
Bitneuker
CICS Moderator
Joined: 07 Nov 2005 Posts: 1104 Location: The Netherlands at Hole 19
|
|
|
|
In addition to Bill's 'performed paragraph' it's possible 'section' is forgotten in the 'AT END PERFORM'. |
|
Back to top |
|
|
kgumraj
Active User
Joined: 01 May 2006 Posts: 151 Location: Hyderabad
|
|
|
|
Hi,
I feel your code might be like this.
Quote: |
PROCEDURE DIVISION.
OPEN.....
...........
...........
READ FILEA
AT END MOVE 'N' TO IND
NOT AT END
PERFORM WRITE-RECORD
END-READ.
WRITE-RECORD.
WRITE REC FROM WS-VAR END-WRITE.
STOP RUN.
|
If this is the case your logic is as follows
Reads a record and writes all the record, when end condition is reached, it is out of READ and hence next para that is WRITE-RECORD para. Hence your last record is writting twice in the file.
to avoid this you can code like this..
Quote: |
PROCEDURE DIVISION.
PERFORM OPEN-PARA.
PERFORM READ-PARA.
PERFORM EXIT-PARA.
OPEN-PARA.
OPEN.....
...........
...........
READ-PARA.
READ FILEA
AT END MOVE 'N' TO IND
NOT AT END
PERFORM WRITE-RECORD
END-READ.
WRITE-RECORD.
WRITE REC FROM WS-VAR END-WRITE.
STOP RUN.
|
|
|
Back to top |
|
|
DavidatK
Active Member
Joined: 22 Nov 2005 Posts: 700 Location: Troy, Michigan USA
|
|
|
|
Premkumar,
Another common mistake is like code that follows:
Code: |
PERFORM PROCESS-DATA THRU PROCESS-EXIT
UNTIL DATA-EOF-SW = ?Y?.
PROCESS-DATA.
READ INPUT-DATE
AT END
MOVE ?Y? TO DATA-EOF-SW
END-READ.
:
:
:
WRITE OUTPUT-DATE.
PROCESS-EXIT.
EXIT.
|
In the case above, you have encountered the EOF but continued on to process and write the last record twice.
A better way would be:
Code: |
PERFORM PROCESS-DATA THRU PROCESS-EXIT
UNTIL DATA-EOF-SW = ?Y?.
PROCESS-DATA.
READ INPUT-DATE
AT END
MOVE ?Y? TO DATA-EOF-SW
GO TO PROCESS-EXIT
END-READ.
:
:
:
WRITE OUTPUT-DATE.
PROCESS-EXIT.
EXIT.
|
The best way is:
Code: |
READ INPUT-DATE
AT END
MOVE ?Y? TO DATA-EOF-SW
END-READ.
PERFORM PROCESS-DATA THRU PROCESS-EXIT
UNTIL DATA-EOF-SW = ?Y?.
PROCESS-DATA.
:
:
:
WRITE OUTPUT-DATE.
READ INPUT-DATE
AT END
MOVE ?Y? TO DATA-EOF-SW
END-READ.
PROCESS-EXIT.
EXIT.
|
No ?GO TO?s and no problem with writing two last records. |
|
Back to top |
|
|
DavidatK
Active Member
Joined: 22 Nov 2005 Posts: 700 Location: Troy, Michigan USA
|
|
|
|
premkumar,
Did you ever get a resolution as to why the last record is being written twice? If yes, Please share with us. |
|
Back to top |
|
|
|