View previous topic :: View next topic
|
Author |
Message |
venkata subbareddy Warnings : 1 New User
Joined: 26 Feb 2007 Posts: 2 Location: chennai
|
|
|
|
i have one file, i need to write last record in another file using CPBol program |
|
Back to top |
|
|
guptae
Moderator
Joined: 14 Oct 2005 Posts: 1208 Location: Bangalore,India
|
|
|
|
Hi there,
Please post new thread for new question |
|
Back to top |
|
|
priyesh.agrawal
Senior Member
Joined: 28 Mar 2005 Posts: 1448 Location: Chicago, IL
|
|
|
|
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 |
|
|
sachin_star3 Warnings : 1 New User
Joined: 30 Sep 2006 Posts: 78 Location: pune
|
|
|
|
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 |
|
|
priyesh.agrawal
Senior Member
Joined: 28 Mar 2005 Posts: 1448 Location: Chicago, IL
|
|
|
|
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 |
|
|
angt
New User
Joined: 01 Jun 2005 Posts: 17 Location: USA
|
|
|
|
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 |
|
|
priyesh.agrawal
Senior Member
Joined: 28 Mar 2005 Posts: 1448 Location: Chicago, IL
|
|
|
|
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. |
|
Back to top |
|
|
h.dinesh
New User
Joined: 06 Dec 2006 Posts: 46 Location: Chennai
|
|
|
|
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 |
|
|
William Thompson
Global Moderator
Joined: 18 Nov 2006 Posts: 3156 Location: Tucson AZ
|
|
|
|
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 |
|
|
h.dinesh
New User
Joined: 06 Dec 2006 Posts: 46 Location: Chennai
|
|
|
|
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 |
|
|
William Thompson
Global Moderator
Joined: 18 Nov 2006 Posts: 3156 Location: Tucson AZ
|
|
|
|
Yes, but AT END, there is no record, nothing to move, nothing in the "record area". |
|
Back to top |
|
|
h.dinesh
New User
Joined: 06 Dec 2006 Posts: 46 Location: Chennai
|
|
|
|
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 |
|
|
William Thompson
Global Moderator
Joined: 18 Nov 2006 Posts: 3156 Location: Tucson AZ
|
|
|
|
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 |
|
|
h.dinesh
New User
Joined: 06 Dec 2006 Posts: 46 Location: Chennai
|
|
|
|
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.
Dinesh |
|
Back to top |
|
|
William Thompson
Global Moderator
Joined: 18 Nov 2006 Posts: 3156 Location: Tucson AZ
|
|
|
|
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 |
|
|
h.dinesh
New User
Joined: 06 Dec 2006 Posts: 46 Location: Chennai
|
|
|
|
Ya, I also got that in manual but cannot figure out why I am not getting error or junk values Can anyone else through some light on this please?
For information: I tried only with PS. |
|
Back to top |
|
|
William Thompson
Global Moderator
Joined: 18 Nov 2006 Posts: 3156 Location: Tucson AZ
|
|
|
|
"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 |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
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 |
|
|
cobolunni
Active User
Joined: 07 Aug 2006 Posts: 127 Location: kerala,india
|
|
|
|
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 |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
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" |
|
Back to top |
|
|
h.dinesh
New User
Joined: 06 Dec 2006 Posts: 46 Location: Chennai
|
|
|
|
Since we would 'always' like to land safely rather than 'most of the time' so, it is better to avoid using second code.
Thanks to all of you for your inputs and clarification. |
|
Back to top |
|
|
|