Empty the VSAM file.

Virtual Storage Access method - ESDS, KSDS, RRDS & LDS. Basic direct access method, Basic sequential -, Queued sequential -, Basic partitioned -, Indexed sequential -, Object - access method.
Post Reply
harish123
Registered Member
Posts: 47
Joined: Thu Jul 04, 2013 10:26 am

Empty the VSAM file.

Post 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.
User avatar
Robert Sample
Global Moderator
Global Moderator
Posts: 1891
Joined: Fri Jun 28, 2013 1:22 am
Location: Dubuque Iowa
United States of America

Re: Empty the VSAM file.

Post 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.
User avatar
BobThomas
Registered Member
Posts: 70
Joined: Sat Jun 15, 2013 11:04 am

Re: Empty the VSAM file.

Post by BobThomas »

If it was REUSE(YES) - can then it be allowed without IDCAMS delete/define?
User avatar
Robert Sample
Global Moderator
Global Moderator
Posts: 1891
Joined: Fri Jun 28, 2013 1:22 am
Location: Dubuque Iowa
United States of America

Re: Empty the VSAM file.

Post 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.
harish123
Registered Member
Posts: 47
Joined: Thu Jul 04, 2013 10:26 am

Re: Empty the VSAM file.

Post by harish123 »

Thanks for the discussion but I'm still looking for the answer...
User avatar
Anuj Dhawan
Founder
Posts: 2801
Joined: Sun Apr 21, 2013 7:40 pm
Location: Mumbai, India
Contact:
India

Re: Empty the VSAM file.

Post 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.
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.
harish123
Registered Member
Posts: 47
Joined: Thu Jul 04, 2013 10:26 am

Re: Empty the VSAM file.

Post by harish123 »

Thanks Robert, Anuj.

Anuj - could you please give an example of using VSAMIO. That will help.
User avatar
Anuj Dhawan
Founder
Posts: 2801
Joined: Sun Apr 21, 2013 7:40 pm
Location: Mumbai, India
Contact:
India

Re: Empty the VSAM file.

Post 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.
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.
harish123
Registered Member
Posts: 47
Joined: Thu Jul 04, 2013 10:26 am

Re: Empty the VSAM file.

Post by harish123 »

This is a great help. Thanks Anuj. :)
User avatar
BobThomas
Registered Member
Posts: 70
Joined: Sat Jun 15, 2013 11:04 am

Re: Empty the VSAM file.

Post by BobThomas »

Thank, I too used this and this did help me.

Thanks,
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 “SMS & VSAM and BDAM, BSAM, QSAM, BPAM, ISAM, OAM.”