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

Rewriting a record multiple times in sequential file.


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
airan002

New User


Joined: 27 Feb 2007
Posts: 8
Location: New delhi

PostPosted: Wed Mar 17, 2010 3:31 am
Reply with quote

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
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Wed Mar 17, 2010 4:21 am
Reply with quote

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
View user's profile Send private message
Craq Giegerich

Senior Member


Joined: 19 May 2007
Posts: 1512
Location: Virginia, USA

PostPosted: Wed Mar 17, 2010 4:26 am
Reply with quote

Just read the record then when you are done rewrite it one time.
Back to top
View user's profile Send private message
airan002

New User


Joined: 27 Feb 2007
Posts: 8
Location: New delhi

PostPosted: Wed Mar 17, 2010 7:07 pm
Reply with quote

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
View user's profile Send private message
Craq Giegerich

Senior Member


Joined: 19 May 2007
Posts: 1512
Location: Virginia, USA

PostPosted: Wed Mar 17, 2010 7:12 pm
Reply with quote

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
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Wed Mar 17, 2010 7:17 pm
Reply with quote

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
View user's profile Send private message
airan002

New User


Joined: 27 Feb 2007
Posts: 8
Location: New delhi

PostPosted: Wed Mar 17, 2010 8:03 pm
Reply with quote

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
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Wed Mar 17, 2010 8:09 pm
Reply with quote

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
View user's profile Send private message
CaptBill

New User


Joined: 28 May 2009
Posts: 20
Location: Oklahoma City, OK USA

PostPosted: Wed Mar 17, 2010 8:21 pm
Reply with quote

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
View user's profile Send private message
Terry Heinze

JCL Moderator


Joined: 14 Jul 2008
Posts: 1249
Location: Richfield, MN, USA

PostPosted: Wed Mar 17, 2010 8:27 pm
Reply with quote

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
View user's profile Send private message
airan002

New User


Joined: 27 Feb 2007
Posts: 8
Location: New delhi

PostPosted: Wed Mar 17, 2010 8:39 pm
Reply with quote

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
View user's profile Send private message
Terry Heinze

JCL Moderator


Joined: 14 Jul 2008
Posts: 1249
Location: Richfield, MN, USA

PostPosted: Wed Mar 17, 2010 8:46 pm
Reply with quote

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
View user's profile Send private message
CaptBill

New User


Joined: 28 May 2009
Posts: 20
Location: Oklahoma City, OK USA

PostPosted: Wed Mar 17, 2010 10:54 pm
Reply with quote

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
View user's profile Send private message
agkshirsagar

Active Member


Joined: 27 Feb 2007
Posts: 691
Location: Earth

PostPosted: Wed Mar 17, 2010 11:08 pm
Reply with quote

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.. icon_smile.gif
Back to top
View user's profile Send private message
CaptBill

New User


Joined: 28 May 2009
Posts: 20
Location: Oklahoma City, OK USA

PostPosted: Thu Mar 18, 2010 10:15 am
Reply with quote

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.. icon_smile.gif


While this approach is valid, remember buffering and that if the program abends, the record in storage might not get written.
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 8
No new posts INCLUDE OMIT COND for Multiple values... DFSORT/ICETOOL 5
No new posts Extracting Variable decimal numbers f... DFSORT/ICETOOL 17
No new posts SFTP Issue - destination file record ... All Other Mainframe Topics 2
No new posts Access to non cataloged VSAM file JCL & VSAM 18
Search our Forums:

Back to Top