Page 1 of 1

Empty the VSAM file.

Posted: Thu Jul 04, 2013 3:50 pm
by harish123
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.

Re: Empty the VSAM file.

Posted: Thu Jul 04, 2013 5:46 pm
by Robert Sample
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.

Posted: Fri Jul 05, 2013 3:08 pm
by BobThomas
If it was REUSE(YES) - can then it be allowed without IDCAMS delete/define?

Re: Empty the VSAM file.

Posted: Fri Jul 05, 2013 3:33 pm
by Robert Sample
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.

Re: Empty the VSAM file.

Posted: Wed Jul 17, 2013 12:29 pm
by harish123
Thanks for the discussion but I'm still looking for the answer...

Re: Empty the VSAM file.

Posted: Wed Jul 17, 2013 3:15 pm
by Anuj Dhawan
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.

Re: Empty the VSAM file.

Posted: Thu Aug 01, 2013 11:46 am
by harish123
Thanks Robert, Anuj.

Anuj - could you please give an example of using VSAMIO. That will help.

Re: Empty the VSAM file.

Posted: Sun Aug 04, 2013 1:56 pm
by Anuj Dhawan
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:

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                                              
//*                                                            
And this step will do what you've asked for:

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                                                
/*
Hope this helps.

Re: Empty the VSAM file.

Posted: Tue Aug 06, 2013 6:02 pm
by harish123
This is a great help. Thanks Anuj. :)

Re: Empty the VSAM file.

Posted: Mon Sep 23, 2013 9:40 am
by BobThomas
Thank, I too used this and this did help me.

Thanks,