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
 

 

Rewriting a record multiple times in sequential file.

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
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    Post subject: Rewriting a record multiple times in sequential file.
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: 7913
Location: Bellevue, IA

PostPosted: Wed Mar 17, 2010 4:21 am    Post subject:
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    Post subject:
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    Post subject:
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    Post subject:
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: 7913
Location: Bellevue, IA

PostPosted: Wed Mar 17, 2010 7:17 pm    Post subject:
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    Post subject:
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: 7913
Location: Bellevue, IA

PostPosted: Wed Mar 17, 2010 8:09 pm    Post subject:
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: 15
Location: Oklahoma City, OK USA

PostPosted: Wed Mar 17, 2010 8:21 pm    Post subject:
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: 1238
Location: Richfield, MN, USA

PostPosted: Wed Mar 17, 2010 8:27 pm    Post subject:
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    Post subject:
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: 1238
Location: Richfield, MN, USA

PostPosted: Wed Mar 17, 2010 8:46 pm    Post subject:
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: 15
Location: Oklahoma City, OK USA

PostPosted: Wed Mar 17, 2010 10:54 pm    Post subject:
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: 685
Location: Earth

PostPosted: Wed Mar 17, 2010 11:08 pm    Post subject:
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: 15
Location: Oklahoma City, OK USA

PostPosted: Thu Mar 18, 2010 10:15 am    Post subject:
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    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

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 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
No new posts Problem in writing Output file vickey_dw COBOL Programming 5 Mon Nov 14, 2016 11:14 pm


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