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

Rewrite commad on sequential file


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

New User


Joined: 07 Dec 2006
Posts: 51
Location: Bloomington

PostPosted: Fri Sep 21, 2007 2:11 am
Reply with quote

Hi,

Could any one please let me know if we can use rewrite commad on sequential file. I am in to a situation where I need to use a sequential file in several programs and keep it in sync with changes.

Is it possible if I open the file in I-O mode and by declaring the copy book lay out in working-storage section, later rewrite the record from working storage record lay out.

This is may be a silly question but I never used rewrite command on a sequential file.

Please provide me if any one have example programs.

Thanks and Regards,
Rajkumar Nerella
Back to top
View user's profile Send private message
CICS Guy

Senior Member


Joined: 18 Jul 2007
Posts: 2146
Location: At my coffee table

PostPosted: Fri Sep 21, 2007 2:37 am
Reply with quote

You have looked at REWRITE in the manual, right?
It looks to me that it can do what you want....

Every time I've faced a situation that I have not yet faced, I try, small test code to "prove" if it is possible or not.....

Go for it......
Back to top
View user's profile Send private message
Rajkumar_n

New User


Joined: 07 Dec 2006
Posts: 51
Location: Bloomington

PostPosted: Fri Sep 21, 2007 3:03 am
Reply with quote

Thanks a lot. Let me try writing a simple sample program.
Back to top
View user's profile Send private message
William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3156
Location: Tucson AZ

PostPosted: Fri Sep 21, 2007 3:06 am
Reply with quote

That's how "real" programmers do it.... icon_lol.gif
Back to top
View user's profile Send private message
balakrishna reddy

Active User


Joined: 13 Jul 2007
Posts: 128
Location: Guntur

PostPosted: Fri Sep 21, 2007 12:47 pm
Reply with quote

Hi Rajkumar,

I have worked on the same type of requirement, You can open that sequential file in i-o mode and if you want to update the file then use rewrite command to do it.

Quote:

Is it possible if I open the file in I-O mode and by declaring the copy book lay out in working-storage section, later rewrite the record from working storage record lay out.



You cannot use the same layout for both working-storage section and the file section. You have to change the variable names.


Please correct me if i am wrong.
Back to top
View user's profile Send private message
saptagiri kintali

New User


Joined: 21 Sep 2007
Posts: 20
Location: chennai

PostPosted: Mon Sep 24, 2007 4:45 pm
Reply with quote

we can update a sequential file but it should contain same length. no changes in length of corresponding rec will not allow.
Back to top
View user's profile Send private message
Rajkumar_n

New User


Joined: 07 Dec 2006
Posts: 51
Location: Bloomington

PostPosted: Fri Sep 28, 2007 11:50 pm
Reply with quote

Hi,

I tried to use rewrite command on a sequential file. I am in to a situations where I need to keep updating a sequential file in two programs.

The program is issuing a file-status of 48 even after opening file in I-O mode.

Could any one please let me know the solution for this incident.

This post is in reference with my previous post about Rewrite comman.

Thanks and Regards,
Rajkumar Nerella
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


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

PostPosted: Fri Sep 28, 2007 11:59 pm
Reply with quote

Hello,

Quote:
I am in to a situations where I need to keep updating a sequential file in two programs.
Are these 2 programs running at the same time?
Back to top
View user's profile Send private message
CICS Guy

Senior Member


Joined: 18 Jul 2007
Posts: 2146
Location: At my coffee table

PostPosted: Sat Sep 29, 2007 12:03 am
Reply with quote

Rajkumar_n wrote:
The program is issuing a file-status of 48 even after opening file in I-O mode.
Two things....
What is in the additional six bytes of file status (always a very good way to get to the bottom of VSAM problems)?
File status 48 says you don't have it opened in I-O mode.....
Maybe the addtitonal three fields will point out the problem....
Maybe you had better prove to your self that the file is opened in I-O mode, a display of all four status fields right after the open could do that.....
Back to top
View user's profile Send private message
Rajkumar_n

New User


Joined: 07 Dec 2006
Posts: 51
Location: Bloomington

PostPosted: Sat Sep 29, 2007 12:57 am
Reply with quote

Hi,

Thanks for all your quick repsonse. I opened the sequential file in I-O mode. My requirement is as shown below.

I have three files

File-A is Input file, File-B is I/O file(VSAM File, File-C is I/O file which is a flat file.

Logic is : Read input file match the record with VSAM AND Flat file

If it is found in VSAM or extract file then rewrite the VSAM record and rewrite the same record in Extract file

If it is not found in VSAM file but not found in extract file then populate date from VSAM file and write the extract record.

Thanks and Regards,
Rajkumar Nerella
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


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

PostPosted: Sat Sep 29, 2007 1:00 am
Reply with quote

Hello,

Ok, we understand the task at hand. . .

Please review the last few replies and answer the questions asked or follow the suggestions made and post the results.

It will also help if you mention which file(s) get(s) the file status 48. . .
Back to top
View user's profile Send private message
CICS Guy

Senior Member


Joined: 18 Jul 2007
Posts: 2146
Location: At my coffee table

PostPosted: Sat Sep 29, 2007 1:02 am
Reply with quote

File status 48 says you don't have it opened in I-O mode.....
What is in the additional six bytes of file status (always a very good way to get to the bottom of VSAM problems)?
Back to top
View user's profile Send private message
Rajkumar_n

New User


Joined: 07 Dec 2006
Posts: 51
Location: Bloomington

PostPosted: Sat Sep 29, 2007 1:48 am
Reply with quote

Hi,

I am not getting this error for VSAM. I am getting this error for Sequential file.

I am not sure if I need to declare file status with 8 bytes of length. I declared it as PIC X(02).

Please assist me.

Thanks and Regards,
Rajkumar Nerella
Back to top
View user's profile Send private message
CICS Guy

Senior Member


Joined: 18 Jul 2007
Posts: 2146
Location: At my coffee table

PostPosted: Sat Sep 29, 2007 2:02 am
Reply with quote

Well, then if it isn't VSAM, don't worry....

File status 48 says you don't have it opened in I-O mode.....

Maybe you had better prove to your self that the file is opened in I-O mode, a display of the status field right after the open could do that.....
Back to top
View user's profile Send private message
Rajkumar_n

New User


Joined: 07 Dec 2006
Posts: 51
Location: Bloomington

PostPosted: Sat Sep 29, 2007 9:54 am
Reply with quote

Hi,

How can I prove that I opened the file in I-O mode. I can prpvide copy of my program. Please let me know if it is possible to assist me where I am going wrong.

Please let me know your mail-id so that I can send the attachment.

I am getting file status 48 on sequential file. But the job is not abending but it is not wrting files to output

Thanks and Regards,
Rajkumar Nerella
Back to top
View user's profile Send private message
CICS Guy

Senior Member


Joined: 18 Jul 2007
Posts: 2146
Location: At my coffee table

PostPosted: Sat Sep 29, 2007 2:53 pm
Reply with quote

Put a display of the file status after the open, close, read and rewrite for the file like:
DISPLAY 'OPEN ' status
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


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

PostPosted: Sat Sep 29, 2007 8:33 pm
Reply with quote

Hello,

Quote:
I am getting file status 48 on sequential file. But the job is not abending but it is not wrting files to output
You do not get an abend because you handled the error in your program. If you did not specify where to put FILE STATUS, the code would have abended.

You can copy/paste from youjr source into youjr reply here. Several of the people who reply to questions are not permitted to download attachments so placing the info "inline" usually works better.

When you put code or jcl in a post, it is best to use the "Code" tab near the top ofthe reply panel. This makes your post more readable and preserves alighment. When yoj have entgered a bit of code, click "Preview" to see how yojr post will appear to the forum. When you are satisfied with yojr post, click "Submit".
Back to top
View user's profile Send private message
anv2005

New User


Joined: 14 Jul 2005
Posts: 44
Location: US

PostPosted: Thu Oct 04, 2007 12:54 am
Reply with quote

Make sure to use the COBOL statement REWRITE instead of WRITE when the sequential file is opened for I-O.

The COBOL statement WRITE results in file status 48 even when the file is opened for I-O.

Regards,
Alex.
Back to top
View user's profile Send private message
murmohk1

Senior Member


Joined: 29 Jun 2006
Posts: 1436
Location: Bangalore,India

PostPosted: Thu Oct 04, 2007 10:21 am
Reply with quote

Alex,

Quote:
Make sure to use the COBOL statement REWRITE instead of WRITE when the sequential file is opened for I-O.

How do you write a new record into the file when opened in I-O mode.

Quote:
The COBOL statement WRITE results in file status 48 even when the file is opened for I-O.

Are you sure about this?
Back to top
View user's profile Send private message
Rajkumar_n

New User


Joined: 07 Dec 2006
Posts: 51
Location: Bloomington

PostPosted: Thu Oct 04, 2007 8:21 pm
Reply with quote

Hi,

Finally I came to know that "WRITE" command and 'REWRITE" command can not be used in the same program. So I switched from sequential file to VSAM file.

But still some where in mind, it is saying we can achived this by using multiple open statements and close statement.

Like

If you want to rewrite the record then open the file in I-O mode and after rewriting close the file.

When you want write a new record open the file in extend mode and close the file after writing the record.

Can any one throw me some light whether this will work.

Thanks and Regards,
Rajkumar Nerella
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


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

PostPosted: Fri Oct 05, 2007 1:48 am
Reply with quote

Hello,

Good design will not have the code opening and closing the file repeatedly.

Is there some reason that the original sequential file cannot be read and a new output file created. If i understand what you want to do (and i may not), you could "change the record read and write the modified record in the new file. If new records need to be written, just write them.

If you show some sample inpujt and what you need for output, we can better offer suggestions.
Back to top
View user's profile Send private message
mmwife

Super Moderator


Joined: 30 May 2003
Posts: 1592

PostPosted: Fri Oct 05, 2007 7:10 pm
Reply with quote

Hi Rajkumar,

Two things haven't been mentioned yet:

You can't REWRITE a tape record.

You can REWRITE a disk rec, but you can't WRITE (insert) a rec into the middle of a file (e.g. between recs 5 ans 6). You can add them to the end of a disk file.

Does either of these apply to what you're trying?
Back to top
View user's profile Send private message
Rajkumar_n

New User


Joined: 07 Dec 2006
Posts: 51
Location: Bloomington

PostPosted: Fri Oct 05, 2007 7:41 pm
Reply with quote

dick scherrer,

I accept with your comment. But in my requirement I need to process the same sequential file through 4 programs.

If I have to create new file in each and every step the process is going to be big.

Thanks and Regards,
Rajkumar Nerella
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


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

PostPosted: Fri Oct 05, 2007 9:51 pm
Reply with quote

Hello,

Depends on how you define "big". The jcl to create the output file (rather than re-write) would be one dd statement "bigger". . .

Without doing any testing, i'd say that reading the file and creating a "new" output will perform as well (probably better) than opening and closing the file repeatedly. Opens and closes require much more system sork than a read or a write.

If you want to do a little test, you might create some test code that in one case opens a file reads a record and closes the file 10000 times. Then do the same thing, but only open the file one time, read 10000 records, and close the file. The difference should demonstrate what i've mentioned.
Back to top
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10886
Location: italy

PostPosted: Fri Oct 05, 2007 10:05 pm
Reply with quote

Hi!

I would like to make a further comment

REWRITE IS DANGEROUS - a la James Bond .. VERY DANGEROUS

in case of program failures/abends/reruns(for_any_reason)
You cannot simply rerun the failing program
but You have to restore the sequential dataset to the initial state,

so...
You need to have an additional step to take a backup before each REWRITING program
and a restore step before the rerun

I would say that having two files is cheaper ( overall cost )

also an additional comment

the REWRITE technique must ( given the aforesaid consideration )
repeat must be approved usually at a high level

regards

e.s
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 Unable to interpret a hex value to De... COBOL Programming 4
No new posts how to eliminate null indicator value... DB2 7
No new posts Format Binary file to EBCDIC JCL & VSAM 4
No new posts Binary File format getting change whi... All Other Mainframe Topics 7
No new posts Compare 2 files and retrive records f... DFSORT/ICETOOL 3
Search our Forums:

Back to Top