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

Write last record in another file using Cobol program


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
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
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: 1208
Location: Bangalore,India

PostPosted: Thu Mar 01, 2007 10:35 am
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: 1448
Location: Chicago, IL

PostPosted: Sun Mar 04, 2007 12:06 pm
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
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: 1448
Location: Chicago, IL

PostPosted: Sun Mar 04, 2007 12:58 pm
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
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: 1448
Location: Chicago, IL

PostPosted: Mon Mar 05, 2007 10:51 am
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
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: 3156
Location: Tucson AZ

PostPosted: Mon Mar 05, 2007 2:28 pm
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
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: 3156
Location: Tucson AZ

PostPosted: Mon Mar 05, 2007 3:34 pm
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
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: 3156
Location: Tucson AZ

PostPosted: Mon Mar 05, 2007 5:38 pm
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
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: 3156
Location: Tucson AZ

PostPosted: Mon Mar 05, 2007 6:16 pm
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
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: 3156
Location: Tucson AZ

PostPosted: Mon Mar 05, 2007 7:43 pm
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

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Mon Mar 05, 2007 8:54 pm
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: 127
Location: kerala,india

PostPosted: Mon Mar 05, 2007 10:08 pm
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

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Mon Mar 05, 2007 10:58 pm
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
h.dinesh

New User


Joined: 06 Dec 2006
Posts: 46
Location: Chennai

PostPosted: Tue Mar 06, 2007 11:54 am
Reply with quote

Since we would 'always' like to land safely rather than 'most of the time' so, it is better to avoid using second code. icon_biggrin.gif

Thanks to all of you for your inputs and clarification.
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 How to split large record length file... DFSORT/ICETOOL 10
No new posts Replace each space in cobol string wi... COBOL Programming 3
No new posts Using API Gateway from CICS program CICS 0
No new posts Extracting Variable decimal numbers f... DFSORT/ICETOOL 17
No new posts COBOL -Linkage Section-Case Sensitive COBOL Programming 1
Search our Forums:

Back to Top