Page 1 of 1
IDENTIFY WEATHER THE KSDS EMPTY OR NOT USING SORT UTILITY
Posted: Mon Aug 14, 2023 7:06 pm
by Maven JJ
HI all,
I have a question HOW TO IDENTIFY WEATHER THE KSDS EMPTY OR NOT USING SORT UTILITY.
Re: IDENTIFY WEATHER THE KSDS EMPTY OR NOT USING SORT UTILITY
Posted: Mon Aug 14, 2023 7:07 pm
by Maven JJ
What I want exactly if the file is empty I want to run the second step like this
Re: IDENTIFY WEATHER THE KSDS EMPTY OR NOT USING SORT UTILITY
Posted: Tue Aug 15, 2023 12:14 am
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.
Re: IDENTIFY WEATHER THE KSDS EMPTY OR NOT USING SORT UTILITY
Posted: Wed Aug 16, 2023 12:08 am
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
/*
Re: IDENTIFY WEATHER THE KSDS EMPTY OR NOT USING SORT UTILITY
Posted: Wed Aug 16, 2023 7:47 am
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!
Re: IDENTIFY WEATHER THE KSDS EMPTY OR NOT USING SORT UTILITY
Posted: Wed Aug 16, 2023 10:40 pm
by Sankar Sabari
So we can use VSAM as input to a SORT step, that's good.
Re: IDENTIFY WEATHER THE KSDS EMPTY OR NOT USING SORT UTILITY
Posted: Thu Aug 17, 2023 4:29 pm
by Anuj Dhawan
Yes, you can.
Re: IDENTIFY WEATHER THE KSDS EMPTY OR NOT USING SORT UTILITY
Posted: Tue Aug 22, 2023 2:40 pm
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.
Re: IDENTIFY WEATHER THE KSDS EMPTY OR NOT USING SORT UTILITY
Posted: Tue Aug 22, 2023 2:41 pm
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.
Re: IDENTIFY WEATHER THE KSDS EMPTY OR NOT USING SORT UTILITY
Posted: Thu Aug 24, 2023 12:33 pm
by Sankar Sabari
Thanks, this is a useful thread. Thanks for sharing all the info.