Not able to overwrite a VSAM file by COBOL program.
Not able to overwrite a VSAM file by COBOL program.
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?
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?
-
- Global Moderator
- Posts: 826
- Joined: Wed Sep 11, 2013 3:57 pm
Re: Not able to overwrite a VSAM file by COBOL program.
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
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
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
- Robert Sample
- Global Moderator
- Posts: 1895
- Joined: Fri Jun 28, 2013 1:22 am
- Location: Dubuque Iowa
Re: Not able to overwrite a VSAM file by COBOL program.
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.
- mickeydusaor
- 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.
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
Re: Not able to overwrite a VSAM file by COBOL program.
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.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
Re: Not able to overwrite a VSAM file by COBOL program.
How do I DELETE the records through program? As I understand, for delete also I need to open the file in I/O mode?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.
Re: Not able to overwrite a VSAM file by COBOL program.
mickeydusaor,
Sorry but I don't understand what you are trying to say? Can you please explain more about it.
Sorry but I don't understand what you are trying to say? Can you please explain more about it.
-
- Global Moderator
- Posts: 826
- Joined: Wed Sep 11, 2013 3:57 pm
Re: Not able to overwrite a VSAM file by COBOL program.
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
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
- Robert Sample
- Global Moderator
- Posts: 1895
- Joined: Fri Jun 28, 2013 1:22 am
- Location: Dubuque Iowa
Re: Not able to overwrite a VSAM file by COBOL program.
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.How do I DELETE the records through program? As I understand, for delete also I need to open the file in I/O mode?
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