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
 

 

last record read was written 2 times in op file

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
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    Post subject: last record read was written 2 times in op file
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    Post subject:
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: 3158
Location: Tucson AZ

PostPosted: Thu Jan 11, 2007 6:56 pm    Post subject: Re: last record read was written 2 times in op file
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: 1105
Location: The Netherlands at Hole 19

PostPosted: Thu Jan 11, 2007 8:11 pm    Post subject:
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    Post subject: Re: last record read was written 2 times in op file
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    Post subject: Re: last record read was written 2 times in op file
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    Post subject: Re: last record read was written 2 times in op file
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    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 Changing of LRECL of a file abdulrafi DFSORT/ICETOOL 2 Fri Mar 24, 2017 3:25 pm
No new posts splitting a file abdulrafi DFSORT/ICETOOL 4 Fri Mar 24, 2017 11:51 am
No new posts Record Not found in AlX but record re... mukun264 COBOL Programming 7 Fri Mar 24, 2017 9:28 am
No new posts Count the length of the record & ... sreekusr DFSORT/ICETOOL 4 Thu Mar 23, 2017 7:52 pm
No new posts Receive a file using PCOMM macro Harald.v.K IBM Tools 0 Thu Mar 23, 2017 6:50 pm


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