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
 

 

Write last record in another file using Cobol program
Goto page 1, 2  Next
 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
venkata subbareddy
Warnings : 1

New User


Joined: 26 Feb 2007
Posts: 2
Location: chennai

PostPosted: Thu Mar 01, 2007 10:31 am    Post subject: i need to write last record in file using cobol program
Reply with quote

i have one file, i need to write last record in another file using CPBol program
Back to top
View user's profile Send private message

guptae

Moderator


Joined: 14 Oct 2005
Posts: 1187
Location: Bangalore,India

PostPosted: Thu Mar 01, 2007 10:35 am    Post subject:
Reply with quote

Hi there,

Please post new thread for new question
Back to top
View user's profile Send private message
priyesh.agrawal

Senior Member


Joined: 28 Mar 2005
Posts: 1452
Location: Chicago, IL

PostPosted: Sun Mar 04, 2007 12:06 pm    Post subject: Re: Write last record in another file using Cobol program
Reply with quote

Read the file in any record structure and check for end of file after very read.
Write the record when encounter EOF.
Back to top
View user's profile Send private message
sachin_star3
Warnings : 1

New User


Joined: 30 Sep 2006
Posts: 78
Location: pune

PostPosted: Sun Mar 04, 2007 12:55 pm    Post subject:
Reply with quote

HI priyesh
but suppose eof condition check and then you move the record then all record all moved ,we just want only last record
how we write the coding?
from-sachin borase
pune
Back to top
View user's profile Send private message
priyesh.agrawal

Senior Member


Joined: 28 Mar 2005
Posts: 1452
Location: Chicago, IL

PostPosted: Sun Mar 04, 2007 12:58 pm    Post subject: Re: Write last record in another file using Cobol program
Reply with quote

sachin wrote:
but suppose eof condition check and then you move the record then all record all moved ,we just want only last record

Sachin... Would not you be reading the records in the same structure again and again or do you use different for each read.

Code:
READ INP-FILE INTO INP-REC-STRUC
AT END
          WRITE OUT-REC FROM INP-REC-STRUC.
Back to top
View user's profile Send private message
angt

New User


Joined: 01 Jun 2005
Posts: 17
Location: USA

PostPosted: Mon Mar 05, 2007 9:54 am    Post subject:
Reply with quote

Priyesh ,

I do not think it's going to work. At end is reached only when last record is read and it tries to read another record from the dataset.

Sachin ,

I will suggest to keep hold of previous record in working storage at end write the O/P file with previous record.
Back to top
View user's profile Send private message
priyesh.agrawal

Senior Member


Joined: 28 Mar 2005
Posts: 1452
Location: Chicago, IL

PostPosted: Mon Mar 05, 2007 10:51 am    Post subject: Re: Write last record in another file using Cobol program
Reply with quote

angt,

Thats a point, and WS-HOLD is a better choie indeed. But wouldn't INP-REC-STRUC be having values from last read when encountered EOF. icon_rolleyes.gif
Back to top
View user's profile Send private message
h.dinesh

New User


Joined: 06 Dec 2006
Posts: 46
Location: Chennai

PostPosted: Mon Mar 05, 2007 1:22 pm    Post subject:
Reply with quote

Hi,

Quote:
Thats a point, and WS-HOLD is a better choie indeed. But wouldn't INP-REC-STRUC be having values from last read when encountered EOF.


INP-REC-STRUC will have values from last read so this should work fine

Code:
READ INP-FILE INTO INP-REC-STRUC
AT END
          WRITE OUT-REC FROM INP-REC-STRUC.


Note: Above I am taking INP-REC-STRUC as Working Storage Var not record structure in FD of i/p file. If you want to use the FD rec structure then use it this way

Code:
READ INP-FILE
AT END
          WRITE OUT-REC FROM INP-REC-STRUC.


where INP-REC-STRUC will be in FD.

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: Mon Mar 05, 2007 2:28 pm    Post subject:
Reply with quote

h.dinesh wrote:
If you want to use the FD rec structure then use it this way
Code:
READ INP-FILE
AT END
          WRITE OUT-REC FROM INP-REC-STRUC.

where INP-REC-STRUC will be in FD.
Dinesh,
I would not count on the input buffer to still be pointed to the last record read, the working storage variable is the only way to insure that you have that record.
Back to top
View user's profile Send private message
h.dinesh

New User


Joined: 06 Dec 2006
Posts: 46
Location: Chennai

PostPosted: Mon Mar 05, 2007 3:20 pm    Post subject:
Reply with quote

William,

The code works fine. I have tried it. I am trying to find if any explanation is given in manual. I have got something but I don't know this will help or not coz it is only a part of explanation of syntax of READ

Quote:
The current record is moved from the record area to the area specified by identifier-1 according to the rules for the MOVE statement without the CORRESPONDING phrase. The size of the current record is determined by rules specified for the RECORD clause. If the file description entry contains a RECORD IS VARYING clause, the implied move is a group move. The implied MOVE statement does not occur if the execution of the READ statement was unsuccessful. Any subscripting or reference modification associated with identifier-1 is evaluated after the record has been read and immediately before it is moved to the data item. The record is available in both the record area and the data item referenced by identifier-1.


Though it doesn't explains fully but I think according to the last line the record area gets populated with record during a READ and from that only the values are moved to the working storage variables.

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: Mon Mar 05, 2007 3:34 pm    Post subject:
Reply with quote

Yes, but AT END, there is no record, nothing to move, nothing in the "record area".
Back to top
View user's profile Send private message
h.dinesh

New User


Joined: 06 Dec 2006
Posts: 46
Location: Chennai

PostPosted: Mon Mar 05, 2007 5:15 pm    Post subject:
Reply with quote

No, I think when it encounters AT END the 'Record Area' will not get populated with anything so the last read record remains.
Back to top
View user's profile Send private message
William Thompson

Global Moderator


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

PostPosted: Mon Mar 05, 2007 5:38 pm    Post subject:
Reply with quote

The "record area" is not an area that gets "populated". It is only a register pointer to a spot in the input buffers (usually two) and the value of that register might or might not get reset or otherwise altered.
Back to top
View user's profile Send private message
h.dinesh

New User


Joined: 06 Dec 2006
Posts: 46
Location: Chennai

PostPosted: Mon Mar 05, 2007 6:09 pm    Post subject:
Reply with quote

William,

By 'Record Area' I was not referring to any area, but I was referring only to variables in FD which gets populated with records after every READ. I am not sure how it works internally.

May be as you mentioned that it is a pointer then may be it doesn't gets 'Reset' and continues to point at the same location when it encounters AT END.

It might not be a justified explanation but the code has worked. I probably need to dig up the manuals to get the correct explanation. But I would suggest you to try the code and possibly explain the reason coz I don't have much knowledge about internal proceessing as you have. icon_sad.gif

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: Mon Mar 05, 2007 6:16 pm    Post subject:
Reply with quote

From the Fine Manual:
Quote:
When the at-end condition occurs, execution of the READ statement is unsuccessful. The contents of the associated record area are undefined and the file position indicator is set to indicate that no valid next record has been established.
For QSAM files, attempts to access or move data into the record area following an unsuccessful read can result in a protection exception.
Back to top
View user's profile Send private message
h.dinesh

New User


Joined: 06 Dec 2006
Posts: 46
Location: Chennai

PostPosted: Mon Mar 05, 2007 6:44 pm    Post subject:
Reply with quote

Ya, I also got that in manual but cannot figure out why I am not getting error or junk values icon_confused.gif Can anyone else through some light on this please?
For information: I tried only with PS.
Back to top
View user's profile Send private message
William Thompson

Global Moderator


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

PostPosted: Mon Mar 05, 2007 7:43 pm    Post subject:
Reply with quote

"the contents of the associated record area are undefined" & "attempts to access or move data into the record area following an unsuccessful read can result in a protection exception"
Undefined: The value of the record pointer may be exactually what you want, fine, but maybe next time the compiler is upgraded, or maybe next time you re-compile your program, or maybe next time you just execute your program, the record pointer may not be what you expected.
Can: Not will, but can, as in maybe or if you are unlucky......
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: Mon Mar 05, 2007 8:54 pm    Post subject:
Reply with quote

Hello,

The code Priyesh originally posted will work ALL of the time. Reading "into" will produce exactly what is needed.

The kinds of errors that may happen is "unpredictable" - it the reference is made to the working-storage "record" all will be well.
Back to top
View user's profile Send private message
cobolunni

Active User


Joined: 07 Aug 2006
Posts: 128
Location: kerala,india

PostPosted: Mon Mar 05, 2007 10:08 pm    Post subject:
Reply with quote

yes its right that predicting the value that the record pointer throws is difficult. But i think most of the time the value in the variable will be preserved when at end condition reaches
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: Mon Mar 05, 2007 10:58 pm    Post subject:
Reply with quote

Hello,

Most of the time is not an acceptable alternative.

How well would you like it if your airline flight landed on a runway "most of the time" icon_confused.gif
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
Goto page 1, 2  Next
Page 1 of 2

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Add PD field from 2nd file to PD in 1st Sushant Garje DFSORT/ICETOOL 6 Thu Dec 01, 2016 4:32 pm
No new posts File Aid to File Manager conversion murali3955 IBM Tools 4 Thu Nov 24, 2016 3:41 pm
No new posts IMS BMP program causes 878 system abend Artemk IMS DB/DC 7 Tue Nov 22, 2016 8:26 pm
No new posts How to convert the VBM file to VB or... Sulabh Agrawal JCL & VSAM 4 Fri Nov 18, 2016 1:04 pm
No new posts CICS Roll back partially - Need to re... dwijadas CICS 4 Wed Nov 16, 2016 4:30 pm


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