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

last record read was written 2 times in op file


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

New User


Joined: 24 Feb 2006
Posts: 8
Location: chennai

PostPosted: Thu Jan 11, 2007 5:50 pm
Reply with quote

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
View user's profile Send private message
h.dinesh

New User


Joined: 06 Dec 2006
Posts: 46
Location: Chennai

PostPosted: Thu Jan 11, 2007 5:58 pm
Reply with quote

premkumar,

Please paste the code so that all can check it.

Dinesh
Back to top
View user's profile Send private message
William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3156
Location: Tucson AZ

PostPosted: Thu Jan 11, 2007 6:56 pm
Reply with quote

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
View user's profile Send private message
Bitneuker

CICS Moderator


Joined: 07 Nov 2005
Posts: 1104
Location: The Netherlands at Hole 19

PostPosted: Thu Jan 11, 2007 8:11 pm
Reply with quote

In addition to Bill's 'performed paragraph' it's possible 'section' is forgotten in the 'AT END PERFORM'.
Back to top
View user's profile Send private message
kgumraj

Active User


Joined: 01 May 2006
Posts: 151
Location: Hyderabad

PostPosted: Fri Jan 12, 2007 2:38 pm
Reply with quote

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
View user's profile Send private message
DavidatK

Active Member


Joined: 22 Nov 2005
Posts: 700
Location: Troy, Michigan USA

PostPosted: Sat Jan 13, 2007 4:29 am
Reply with quote

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
View user's profile Send private message
DavidatK

Active Member


Joined: 22 Nov 2005
Posts: 700
Location: Troy, Michigan USA

PostPosted: Wed Jan 17, 2007 2:28 am
Reply with quote

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
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 FTP VB File from Mainframe retaining ... JCL & VSAM 4
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
No new posts Error to read log with rexx CLIST & REXX 11
No new posts Extracting Variable decimal numbers f... DFSORT/ICETOOL 17
Search our Forums:

Back to Top