Page 1 of 1

Empty a file without deleting the file.

Posted: Tue Nov 03, 2015 11:02 am
by Rahul Dhoble
Hi,

In a JOb step I need to delete the content of a dataset but I don't want to delete the dataset itself. How is it possible to do? Can IDCAMS or IEFBR14 do this? Please help.

Re: Empty a file without deleting the file.

Posted: Tue Nov 03, 2015 1:35 pm
by zprogrammer
Hi,

You could delete and recreate the dataset

Re: Empty a file without deleting the file.

Posted: Tue Nov 03, 2015 2:21 pm
by nicc
Can IDCAMS or IEFBR14 do this?
What happened when you tried?

You must understand about IEFBR14 - it does absolutely nothing, zilch, zero, sod all apart from set a return code of zero.

You could write a little program that will open the dataset in output mode and then close it again. That should reset the end-of-file indicator. And, yes, you can make it generic.

Re: Empty a file without deleting the file.

Posted: Tue Nov 03, 2015 5:24 pm
by enrico-sorichetti
the question is legitimate,
I have seen many places where the users can update a dataset but cannot delete/allocate it
so for them there might be the need to <empty> a dataset

for a VSAM cluster only if it has been defined with the REUSE attribute

for a PS dataset a simple iebgener with a DUMMY input DD will do

Re: Empty a file without deleting the file.

Posted: Tue Nov 03, 2015 7:08 pm
by zprogrammer
Hi Enrico,

Ok,I understand. In such cases DUMMY overwrite would come handy

Re: Empty a file without deleting the file.

Posted: Tue Nov 03, 2015 11:50 pm
by Robert Sample
IEFBR14 cannot do this -- it does not open the data set.

For VSAM, the REUSE option comes into play. Without it, what you want to do cannot be done. For sequential, IDCAMS can -- REPRO from a DD DUMMY to the data set with DISP=OLD specified.

Re: Empty a file without deleting the file.

Posted: Sat Jul 15, 2017 1:33 am
by raazankeet
You may use the below JCL

Code: Select all

//EMPTY    EXEC PGM=SORT                         
//SYSOUT   DD SYSOUT=*                           
//SORTIN   DD DSN=TSUE34S.ANKIT.Y2017,DISP=SHR   ----> Input file with No records and same DCB Attributes  
//SORTOUT  DD DSN=TSUE34S.ANKIT.G2017,DISP=OLD   ----> File to be emptied out, see the DISP used  
//STDOUT  DD  SYSOUT=*                           
//SYSIN DD   *                                   
  SORT FIELDS=COPY

Re: Empty a file without deleting the file.

Posted: Sat Jul 15, 2017 1:50 am
by Robert Sample
raazankeet, why not

Code: Select all

//EMPTY    EXEC PGM=SORT                         
//SYSOUT   DD SYSOUT=*                           
//SORTIN   DD DUMMY,LRECL=?,BLKSIZE=?
//SORTOUT  DD DSN=TSUE34S.ANKIT.G2017,DISP=OLD   ----> File to be emptied out, see the DISP used  
//STDOUT  DD  SYSOUT=*                           
//SYSIN DD   *                                   
  SORT FIELDS=COPY
instead of having to allocate an empty data set? And your SORT JCL is no improvement upon the previously suggested IDCAMS or IEBGENER solutions -- you've merely provided another way to do the same thing.

Code: Select all

//EMPTY    EXEC PGM=IEBGENER
//SYSPRINT DD   SYSOUT=*
//SYSIN    DD   DUMMY
//SYSUT1   DD   DUMMY,LRECL=?,BLKSIZE=?
//SYSUT2   DD   DISP=OLD,DSN=TSUE345.ANKIT.G2017
requires fewer lines of coding and no parameter to do the same thing.

Also, after a year and a half the likelihood of your solution being helpful is pretty close to zero. And there are plenty of other examples in this and other fora on how to delete the records in a data set without deleting the data set. So other than raising your posting count, you haven't really contributed much to the topic.

Re: Empty a file without deleting the file.

Posted: Sun Jul 16, 2017 10:00 pm
by raazankeet
Robert Sample wrote: So other than raising your posting count, you haven't really contributed much to the topic.
I'm not sure how the posting count will help me or anyone by any means!

I replied what came to my mind after seeing the question. You may agree that there are multiple ways to solve each problem.
Which way to go, this depends on many factors.

However, I must say that I was not aware of the

Code: Select all

LRECL=?,BLKSIZE=?
.
Thanks for this!!!

Re: Empty a file without deleting the file.

Posted: Mon Jul 17, 2017 2:47 am
by Robert Sample
The question marks are filled in with the appropriate values, of course; you don't want to try using LRECL=? in an actual job.