Not able to overwrite a VSAM file by COBOL program.

OS/VS COBOL, COBOL II, Enterprise COBOL for z/OS. OpenCOBOL and OOCobol.
Post Reply
User avatar
sachin12
Registered Member
Posts: 10
Joined: Tue Dec 02, 2014 10:11 am

Not able to overwrite a VSAM file by COBOL program.

Post by sachin12 »

Hi,

For a COBOL program a VSAM file is an output. File is opened in output mode. My intention is that whever I run the program, the file should get overwritten with new values. For testing, first time I create the file and write the record, until here all is good but when I execute the program second time, the vsam file is not over written with new values. So, to test every time I am deleting and creating the VSAM file using IDCAMS before executing this program.

Any way to overwrite the VSAM file in the COBOL program itself?
enrico-sorichetti
Global Moderator
Global Moderator
Posts: 826
Joined: Wed Sep 11, 2013 3:57 pm

Re: Not able to overwrite a VSAM file by COBOL program.

Post by enrico-sorichetti »

Yes, it is possible, but it is better to speak to Your support to check if that possibility is allowed/supported.
1) as a company standard
2) for the dataset You are dealing with
cheers
enrico
When I tell somebody to RTFM or STFW I usually have the page open in another tab/window of my browser,
so that I am sure that the information requested can be reached with a very small effort 8-)
User avatar
Robert Sample
Global Moderator
Global Moderator
Posts: 1895
Joined: Fri Jun 28, 2013 1:22 am
Location: Dubuque Iowa
United States of America

Re: Not able to overwrite a VSAM file by COBOL program.

Post by Robert Sample »

I don't think your approach makes much sense. If you need to update the records in a VSAM data set after they have been written (in a COBOL program), you either need to DELETE them and then WRITE the records again, or you need to REWRITE the records. Neither of these will work with the file opened for OUTPUT -- you need to open the file I-O instead. For what you are doing, deleting the VSAM data set and recreating it probably makes the most sense.
User avatar
mickeydusaor
Forum Moderator
Forum Moderator
Posts: 27
Joined: Fri Aug 28, 2015 10:11 pm
Location: Salem, Oregon

Re: Not able to overwrite a VSAM file by COBOL program.

Post by mickeydusaor »

Code: Select all

//step0001 EXEC PGM=IDCAMS 
//INFILE     DD DSN=XXX.YYY.ZZZ,DISP=SHR 
//SYSIN     DD * 
PRINT INFILE(INFILE) COUNT(1) 
//*
// if step0001.rc eq 0
//step0099 exec pgm=xxxxxxx
// endif
Coded
User avatar
sachin12
Registered Member
Posts: 10
Joined: Tue Dec 02, 2014 10:11 am

Re: Not able to overwrite a VSAM file by COBOL program.

Post by sachin12 »

enrico-sorichetti wrote:Yes, it is possible, but it is better to speak to Your support to check if that possibility is allowed/supported.
1) as a company standard
2) for the dataset You are dealing with
Support? Did you mean to talk to the team lead. If yes, his answer is not very good, as he does not have much experience with VSAM processing.
User avatar
sachin12
Registered Member
Posts: 10
Joined: Tue Dec 02, 2014 10:11 am

Re: Not able to overwrite a VSAM file by COBOL program.

Post by sachin12 »

Robert Sample wrote:I don't think your approach makes much sense. If you need to update the records in a VSAM data set after they have been written (in a COBOL program), you either need to DELETE them and then WRITE the records again, or you need to REWRITE the records. Neither of these will work with the file opened for OUTPUT -- you need to open the file I-O instead. For what you are doing, deleting the VSAM data set and recreating it probably makes the most sense.
How do I DELETE the records through program? As I understand, for delete also I need to open the file in I/O mode?
User avatar
sachin12
Registered Member
Posts: 10
Joined: Tue Dec 02, 2014 10:11 am

Re: Not able to overwrite a VSAM file by COBOL program.

Post by sachin12 »

mickeydusaor,

Sorry but I don't understand what you are trying to say? Can you please explain more about it.
enrico-sorichetti
Global Moderator
Global Moderator
Posts: 826
Joined: Wed Sep 11, 2013 3:57 pm

Re: Not able to overwrite a VSAM file by COBOL program.

Post by enrico-sorichetti »

Evaluate with Your support the applicability of the REUSE clause when defining the cluster
REUSE / NOREUSE
REUSE parameter allows clusters to be reset to empty status without deleting and re-defining them.
cheers
enrico
When I tell somebody to RTFM or STFW I usually have the page open in another tab/window of my browser,
so that I am sure that the information requested can be reached with a very small effort 8-)
User avatar
Robert Sample
Global Moderator
Global Moderator
Posts: 1895
Joined: Fri Jun 28, 2013 1:22 am
Location: Dubuque Iowa
United States of America

Re: Not able to overwrite a VSAM file by COBOL program.

Post by Robert Sample »

How do I DELETE the records through program? As I understand, for delete also I need to open the file in I/O mode?
You need to learn how to read the manuals. The Enterprise COBOL Language Reference manual describes every PROCEDURE DIVISION verb, the syntax for it, and frequently there are examples in it or the Language Guide manual. If you had read the manual, you would have discovered the DELETE statement exists in COBOL and can be used with VSAM KSDS data sets. The Language Guide explicitly tells you that the DELETE verb can only be used for files OPEN I-O.
Post Reply

Create an account or sign in to join the discussion

You need to be a member in order to post a reply

Create an account

Not a member? register to join our community
Members can start their own topics & subscribe to topics
It’s free and only takes a minute

Register

Sign in

Return to “IBM COBOL, GnuCOBOL (OpenCOBOL), OOCobol.”