Empty a file without deleting the file.

JES2/3, JCL, utilities.
Post Reply
Rahul Dhoble
New Member
Posts: 6
Joined: Sun Apr 27, 2014 10:47 am

Empty a file without deleting the file.

Post 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.
zprogrammer
Global Moderator
Global Moderator
Posts: 588
Joined: Wed Nov 20, 2013 11:53 am
Location: Mars

Re: Empty a file without deleting the file.

Post by zprogrammer »

Hi,

You could delete and recreate the dataset
zprogrammer
nicc
Global Moderator
Global Moderator
Posts: 691
Joined: Wed Apr 23, 2014 8:45 pm

Re: Empty a file without deleting the file.

Post 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.
Regards
Nic
enrico-sorichetti
Global Moderator
Global Moderator
Posts: 837
Joined: Wed Sep 11, 2013 3:57 pm

Re: Empty a file without deleting the file.

Post 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
cheers
enrico
When I tell somebody to RTFM or STFW I usually have the page open in another tab/window of my browser,
so that I am sure that the information requested can be reached with a very small effort 8-)
zprogrammer
Global Moderator
Global Moderator
Posts: 588
Joined: Wed Nov 20, 2013 11:53 am
Location: Mars

Re: Empty a file without deleting the file.

Post by zprogrammer »

Hi Enrico,

Ok,I understand. In such cases DUMMY overwrite would come handy
zprogrammer
User avatar
Robert Sample
Global Moderator
Global Moderator
Posts: 1900
Joined: Fri Jun 28, 2013 1:22 am
Location: Dubuque Iowa
United States of America

Re: Empty a file without deleting the file.

Post 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.
raazankeet
New Member
Posts: 5
Joined: Wed Jul 06, 2016 8:59 pm

Re: Empty a file without deleting the file.

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

Re: Empty a file without deleting the file.

Post 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.
raazankeet
New Member
Posts: 5
Joined: Wed Jul 06, 2016 8:59 pm

Re: Empty a file without deleting the file.

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

Re: Empty a file without deleting the file.

Post 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.
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 “JCL - Job Control Language.”