View previous topic :: View next topic
|
Author |
Message |
airan002
New User
Joined: 27 Feb 2007 Posts: 8 Location: New delhi
|
|
|
|
Hi,
I have a sequential file which has only one record. This record needs to be updated multiple times during the processing of the COBOL program.
I can do it, if the i have a VSAM file instead of sequential file. But as per client we should not use the VSAM file.
How can i do it in COBOL ?
Thanks,
Neeraj Kumar |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8700 Location: Dubuque, Iowa, USA
|
|
|
|
The COBOL REWRITE statement supports sequential direct access files. Click the manuals link at the top of the page, find the COBOL Language Reference manual, and read up on REWRITE -- especially section 6.2.31.4 on sequential files.
However, this design may be flawed since if you only have one record in the file, repeatedly reading and rewriting the record implies closing and opening the file repeatedly -- which is extremely poor design, causes long run times, and excessive overhead on the system. |
|
Back to top |
|
|
Craq Giegerich
Senior Member
Joined: 19 May 2007 Posts: 1512 Location: Virginia, USA
|
|
|
|
Just read the record then when you are done rewrite it one time. |
|
Back to top |
|
|
airan002
New User
Joined: 27 Feb 2007 Posts: 8 Location: New delhi
|
|
|
|
Is there any way, i can rewrite the single record multiple times (In the sequential file) without opening and closing.
It may not be possible, But before suggesting the client. I want to make sure, i have tried all the options. |
|
Back to top |
|
|
Craq Giegerich
Senior Member
Joined: 19 May 2007 Posts: 1512 Location: Virginia, USA
|
|
|
|
WHY would you want to rewrite the record multiple times? If this is to keep track of your position to do a restart this is a very poor way to do that! |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8700 Location: Dubuque, Iowa, USA
|
|
|
|
If you had read the manual reference I provided, you would have seen
Quote: |
6.2.31.4 Sequential files
For files in the sequential access mode, the last prior input/output statement executed for this file must be a successfully executed READ statement. When the REWRITE statement is executed, the record retrieved by that READ statement is logically replaced. |
To REWRITE the record, you must READ the record. If the file has only record, how can you read the same record a second time? You close the file, then open it.
In other words, you have 3 choices:
1. Use VSAM file with READ of the key before each REWRITE
2. Use sequential file with close and open and read after each REWRITE
3. Tell whoever gave you the assignment that it cannot be done as specified.
Since you've already said #1 is not possible, and we strongly recommend against #2, you're left with #3. |
|
Back to top |
|
|
airan002
New User
Joined: 27 Feb 2007 Posts: 8 Location: New delhi
|
|
|
|
Thanks,
I will suggest client with all the 3 options. I tried to explain them yesterday but they were stuck with their thinking.
Now, I am sure..it can not be done using sequential with open/close.
Thanks, |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8700 Location: Dubuque, Iowa, USA
|
|
|
|
No, it CAN be done if you do CLOSE and OPEN followed by a READ of the sequential file. However, this is extremely expensive in terms of system resources used and will usually increase elapsed times drastically for any kind of volume production data. Run times may go from minutes to hours (hours may go to days) if repeatedly closing and opening a file is used in the job. |
|
Back to top |
|
|
CaptBill
New User
Joined: 28 May 2009 Posts: 20 Location: Oklahoma City, OK USA
|
|
|
|
Craq Giegerich wrote: |
Just read the record then when you are done rewrite it one time. |
Why not just read the record once and put it in a WORKING-STORAGE area as implied by the above statement. Make your updates to this W-S area and when the job is complete, THEN rewrite the record? |
|
Back to top |
|
|
Terry Heinze
JCL Moderator
Joined: 14 Jul 2008 Posts: 1248 Location: Richfield, MN, USA
|
|
|
|
You can easily prove to yourself just exactly how expensive the OPEN/CLOSE multiple times can be as pointed out by Robert by a simple test program to OPEN/READ/REWRITE/CLOSE your file. Set a counter to a large number and fire it off. |
|
Back to top |
|
|
airan002
New User
Joined: 27 Feb 2007 Posts: 8 Location: New delhi
|
|
|
|
Working storage is not feasible. If the job abends with some system for example SB37 or timeout problem. It will not be written into the output file. |
|
Back to top |
|
|
Terry Heinze
JCL Moderator
Joined: 14 Jul 2008 Posts: 1248 Location: Richfield, MN, USA
|
|
|
|
At one of my previous sites, the standard was to use a "bypass" file consisting of a single record containing the key of the records being processed. In that case the key was policy number. The bypass file was opened, read, rewritten, and closed for each policy number of the driving input file. This method allowed for rerunning and bypassing the problem policy (even a S0C7 abend) and was attended to the following morning. This prevented most 3 AM calls to the supporting folks. It was expensive, but they felt the advantages were worth the extra elapsed time. |
|
Back to top |
|
|
CaptBill
New User
Joined: 28 May 2009 Posts: 20 Location: Oklahoma City, OK USA
|
|
|
|
airan002 wrote: |
Working storage is not feasible. If the job abends with some system for example SB37 or timeout problem. It will not be written into the output file. |
So write the program to their specifications but tell them the run times will be especially long do to their requiring you to open and close the file many times. |
|
Back to top |
|
|
agkshirsagar
Active Member
Joined: 27 Feb 2007 Posts: 691 Location: Earth
|
|
|
|
Why not write multiple records and consider only the latest one to be valid one? Or you could add a sort step after the program to delete all records but the latest one?
It will be good if you could elaborate more on the requirement. How this file will be utilized later? (I am thinking of a log file/restart file). Then we may be able to give better suggestions.
I wouldn't be caught dead writing a program with multiple open close on the same file.. |
|
Back to top |
|
|
CaptBill
New User
Joined: 28 May 2009 Posts: 20 Location: Oklahoma City, OK USA
|
|
|
|
agkshirsagar wrote: |
Why not write multiple records and consider only the latest one to be valid one? Or you could add a sort step after the program to delete all records but the latest one?
It will be good if you could elaborate more on the requirement. How this file will be utilized later? (I am thinking of a log file/restart file). Then we may be able to give better suggestions.
I wouldn't be caught dead writing a program with multiple open close on the same file.. |
While this approach is valid, remember buffering and that if the program abends, the record in storage might not get written. |
|
Back to top |
|
|
|