Empty the VSAM file.
Empty the VSAM file.
If VSAM File(KSDS)is defined as REUSE=No,is there any possibility to 'empty' the File using SORT, if yes kindly help me on this.
- Robert Sample
- Global Moderator
- Posts: 1891
- Joined: Fri Jun 28, 2013 1:22 am
- Location: Dubuque Iowa
Re: Empty the VSAM file.
With REUSE(NO) for a VSAM file, you will need to delete / define the file to empty it. This uses IDCAMS, not SORT.
Re: Empty the VSAM file.
If it was REUSE(YES) - can then it be allowed without IDCAMS delete/define?
- Robert Sample
- Global Moderator
- Posts: 1891
- Joined: Fri Jun 28, 2013 1:22 am
- Location: Dubuque Iowa
Re: Empty the VSAM file.
I don't think using SORT would allow one to empty a VSAM file. A program could, by reading each record sequentially and then deleting that record. I'm not sure if sorting an empty file into the VSAM file would delete the records or not.
- Anuj Dhawan
- Founder
- Posts: 2801
- Joined: Sun Apr 21, 2013 7:40 pm
- Location: Mumbai, India
- Contact:
Re: Empty the VSAM file.
This can be done using SORT, howevdr, there are couple of "IFs" you've to answer first:
If the KSDS is defined with REUSE (in your case it is Yes), you can use DFSORT's VSAMIO and RESET options along with the OMIT and SORT statements to delete specific records from the KSDS. The VSAMIO option, when VSAM file defined with REUSE, allows the same VSAM file to be used for input and output.
However, NOTE that this kind of "sort" is not recommended unless you can afford to lose the VSAM file if something goes wrong. It is usally advised to go from the VSAM file to a temporary file ("flat file", QSAM) and then from the temporary file back to the VSAM file.
If the KSDS is defined with REUSE (in your case it is Yes), you can use DFSORT's VSAMIO and RESET options along with the OMIT and SORT statements to delete specific records from the KSDS. The VSAMIO option, when VSAM file defined with REUSE, allows the same VSAM file to be used for input and output.
However, NOTE that this kind of "sort" is not recommended unless you can afford to lose the VSAM file if something goes wrong. It is usally advised to go from the VSAM file to a temporary file ("flat file", QSAM) and then from the temporary file back to the VSAM file.
Thanks,
Anuj
Disclaimer: My comments on this website are my own and do not represent the opinions or suggestions of any other person or business entity, in any way.
Anuj
Disclaimer: My comments on this website are my own and do not represent the opinions or suggestions of any other person or business entity, in any way.
Re: Empty the VSAM file.
Thanks Robert, Anuj.
Anuj - could you please give an example of using VSAMIO. That will help.
Anuj - could you please give an example of using VSAMIO. That will help.
- Anuj Dhawan
- Founder
- Posts: 2801
- Joined: Sun Apr 21, 2013 7:40 pm
- Location: Mumbai, India
- Contact:
Re: Empty the VSAM file.
As per your initial post where you asked to 'empty' the same VSAM data-set. I, for one, suggest to take the back up first:
And this step will do what you've asked for:
Hope this helps.
Code: Select all
//**********************************************************
//* BACKUP COPY OF THE VSAM FILE *
//**********************************************************
//STEP0100 EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SORTIN DD DSN=INPUT.VSAM.FILE,
// DISP=SHR
//SORTOUT DD DSN=MY.PS.OUTPUT.FILE,
// DISP=(NEW,CATLG,DELETE),
// SPACE=(CYL,(500,500),RLSE)
//SYSIN DD *
SORT FIELDS=COPY
//*
Code: Select all
//**********************************************************
//* EMPTY THE INPUT VSAM FILE *
//**********************************************************
//STEP0200 EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//DFSPARM DD *
OPTION VSAMIO,RESET
//SORTIN DD DSN=INPUT.VSAM.FILE,
// DISP=SHR
//SORTOUT DD DSN=INPUT.VSAM.FILE,
// DISP=SHR
//SYSIN DD *
SORT FIELDS=(1,1,CH,A)
OMIT COND=ALL
/*
Thanks,
Anuj
Disclaimer: My comments on this website are my own and do not represent the opinions or suggestions of any other person or business entity, in any way.
Anuj
Disclaimer: My comments on this website are my own and do not represent the opinions or suggestions of any other person or business entity, in any way.
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