IDENTIFY WEATHER THE KSDS EMPTY OR NOT USING SORT UTILITY

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
Maven JJ
Registered Member
Posts: 14
Joined: Thu May 19, 2016 3:36 pm

IDENTIFY WEATHER THE KSDS EMPTY OR NOT USING SORT UTILITY

Post by Maven JJ »

HI all,

I have a question HOW TO IDENTIFY WEATHER THE KSDS EMPTY OR NOT USING SORT UTILITY.
Maven JJ
Registered Member
Posts: 14
Joined: Thu May 19, 2016 3:36 pm

Re: IDENTIFY WEATHER THE KSDS EMPTY OR NOT USING SORT UTILITY

Post by Maven JJ »

What I want exactly if the file is empty I want to run the second step like this
User avatar
zum13
Registered Member
Posts: 89
Joined: Thu May 04, 2023 12:58 am

Re: IDENTIFY WEATHER THE KSDS EMPTY OR NOT USING SORT UTILITY

Post by zum13 »

DFSORT only really likes sequential datasets, so using it do do this check on a VSAM file isn't doable (unless something has changed recently). What you need is an IDCAMS "PRINT" command:

Code: Select all

//STEP1   EXEC PGM=IDCAMS 
//SYSPRINT  DD SYSOUT=* 
//DD1       DD DSN=your.vsam.dataset,DISP=SHR
//SYSIN     DD * 
 PRINT INFILE(DD1) COUNT(1) 
This will try to print the first record in the dataset. If there's nothing in there, it'll drop a return code 160 from the VSAM open which will cause IDCAMS to return CC 12. If there's a matching record, you'll get CC 0.
User avatar
Anuj Dhawan
Founder
Posts: 2802
Joined: Sun Apr 21, 2013 7:40 pm
Location: Mumbai, India
Contact:
India

Re: IDENTIFY WEATHER THE KSDS EMPTY OR NOT USING SORT UTILITY

Post by Anuj Dhawan »

Along with that, SORT products can also work with VSAM:

Code: Select all

//STEP1    EXEC  PGM=ICETOOL
//TOOLMSG   DD  SYSOUT=*
//DFSMSG    DD  SYSOUT=*
//IN DD DSN=...  input-vsam-dataset
//TOOLIN DD *
COUNT FROM(IN) EMPTY RC4
/*
This produces RC as 4, if the input VSAM dataset is empty.

Another variation:

Code: Select all

/STEP1 EXEC PGM=ICETOOL
//TOOLMSG DD SYSOUT=*
//DFSMSG DD SYSOUT=*
//IN DD DSN=...  VSAM data set
//TOOLIN DD *
* SET RC=12 IF THE 'IN' DATA SET IS EMPTY, OR
* SET RC=0 IF THE 'IN' DATA SET IS NOT EMPTY
COUNT FROM(IN) EMPTY USING(CTL1)
/*
//CTL1CNTL DD *
   OPTION VSAMEMT
/*
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.
User avatar
zum13
Registered Member
Posts: 89
Joined: Thu May 04, 2023 12:58 am

Re: IDENTIFY WEATHER THE KSDS EMPTY OR NOT USING SORT UTILITY

Post by zum13 »

I stand corrected... DFSORT can read VSAM. I'll admit that it's been a very long time since I last tried (and failed) to use it with anything other than a sequential file!
Sankar Sabari
Registered Member
Posts: 22
Joined: Thu Mar 17, 2016 9:54 pm

Re: IDENTIFY WEATHER THE KSDS EMPTY OR NOT USING SORT UTILITY

Post by Sankar Sabari »

So we can use VSAM as input to a SORT step, that's good.
User avatar
Anuj Dhawan
Founder
Posts: 2802
Joined: Sun Apr 21, 2013 7:40 pm
Location: Mumbai, India
Contact:
India

Re: IDENTIFY WEATHER THE KSDS EMPTY OR NOT USING SORT UTILITY

Post by Anuj Dhawan »

Yes, you can.
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.
Maven JJ
Registered Member
Posts: 14
Joined: Thu May 19, 2016 3:36 pm

Re: IDENTIFY WEATHER THE KSDS EMPTY OR NOT USING SORT UTILITY

Post by Maven JJ »

zum13 wrote: Tue Aug 15, 2023 12:14 am DFSORT only really likes sequential datasets, so using it do do this check on a VSAM file isn't doable (unless something has changed recently). What you need is an IDCAMS "PRINT" command:

Code: Select all

//STEP1   EXEC PGM=IDCAMS 
//SYSPRINT  DD SYSOUT=* 
//DD1       DD DSN=your.vsam.dataset,DISP=SHR
//SYSIN     DD * 
 PRINT INFILE(DD1) COUNT(1) 
This will try to print the first record in the dataset. If there's nothing in there, it'll drop a return code 160 from the VSAM open which will cause IDCAMS to return CC 12. If there's a matching record, you'll get CC 0.
Thank you, this is working for me.
Maven JJ
Registered Member
Posts: 14
Joined: Thu May 19, 2016 3:36 pm

Re: IDENTIFY WEATHER THE KSDS EMPTY OR NOT USING SORT UTILITY

Post by Maven JJ »

Anuj Dhawan wrote: Wed Aug 16, 2023 12:08 am Along with that, SORT products can also work with VSAM:

Code: Select all

//STEP1    EXEC  PGM=ICETOOL
//TOOLMSG   DD  SYSOUT=*
//DFSMSG    DD  SYSOUT=*
//IN DD DSN=...  input-vsam-dataset
//TOOLIN DD *
COUNT FROM(IN) EMPTY RC4
/*
This produces RC as 4, if the input VSAM dataset is empty.

Another variation:

Code: Select all

/STEP1 EXEC PGM=ICETOOL
//TOOLMSG DD SYSOUT=*
//DFSMSG DD SYSOUT=*
//IN DD DSN=...  VSAM data set
//TOOLIN DD *
* SET RC=12 IF THE 'IN' DATA SET IS EMPTY, OR
* SET RC=0 IF THE 'IN' DATA SET IS NOT EMPTY
COUNT FROM(IN) EMPTY USING(CTL1)
/*
//CTL1CNTL DD *
   OPTION VSAMEMT
/*
Thank you Anuj, this also works.
Sankar Sabari
Registered Member
Posts: 22
Joined: Thu Mar 17, 2016 9:54 pm

Re: IDENTIFY WEATHER THE KSDS EMPTY OR NOT USING SORT UTILITY

Post by Sankar Sabari »

Thanks, this is a useful thread. Thanks for sharing all the info.
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.”