Page 1 of 1
Not able to overwrite a VSAM file by COBOL program.
Posted: Thu Sep 03, 2015 2:22 pm
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?
Re: Not able to overwrite a VSAM file by COBOL program.
Posted: Thu Sep 03, 2015 4:31 pm
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
Re: Not able to overwrite a VSAM file by COBOL program.
Posted: Thu Sep 03, 2015 5:59 pm
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.
Re: Not able to overwrite a VSAM file by COBOL program.
Posted: Thu Sep 03, 2015 7:39 pm
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
Re: Not able to overwrite a VSAM file by COBOL program.
Posted: Mon Sep 07, 2015 3:16 pm
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.
Re: Not able to overwrite a VSAM file by COBOL program.
Posted: Mon Sep 07, 2015 3:18 pm
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?
Re: Not able to overwrite a VSAM file by COBOL program.
Posted: Mon Sep 07, 2015 3:18 pm
by sachin12
mickeydusaor,
Sorry but I don't understand what you are trying to say? Can you please explain more about it.
Re: Not able to overwrite a VSAM file by COBOL program.
Posted: Mon Sep 07, 2015 3:28 pm
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.
Re: Not able to overwrite a VSAM file by COBOL program.
Posted: Mon Sep 07, 2015 6:53 pm
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.