Page 1 of 1
How to count No. of Records in Dataset using Sort?
Posted: Thu Jul 04, 2013 4:32 pm
by harish123
Hi
Using JCL/SORT how can we find the total number of records in a dataset. Are there any tools specific for this or can we use SYNCSORT to do this. If so how to do that?
Can some one help me.
Re: How to count No. of Records in Dataset using Sort?
Posted: Thu Jul 04, 2013 5:55 pm
by Robert Sample
There are multiple ways to do this. One way would be to add a sequence number field to the record. Or add a constant 1 to the record and sum them. Or just use a COPY and look at the job output to see how many records SORT found.
The answer to your question partly depends upon what you meant -- do you want the count in a trailer record, or just printed, or stored on the last record, or something else?
Re: How to count No. of Records in Dataset using Sort?
Posted: Fri Jul 05, 2013 3:06 pm
by BobThomas
Should not REXX be used here?
Re: How to count No. of Records in Dataset using Sort?
Posted: Fri Jul 05, 2013 4:42 pm
by Robert Sample
If the data set has about 2 billion records, I would NOT recommend using REXX.
Re: How to count No. of Records in Dataset using Sort?
Posted: Sun Jul 07, 2013 1:41 am
by Anuj Dhawan
I'm in agreement with Robert - for huge data sets, (ad Robert has already indicated what is "Huge") - REXX is not a good choice.
Re: How to count No. of Records in Dataset using Sort?
Posted: Wed Jul 17, 2013 12:27 pm
by harish123
Thanks Robert and Anuj.
I intend to use this for my daily work - it's not a real requirement though. I'd like to use Sort for this.
Re: How to count No. of Records in Dataset using Sort?
Posted: Wed Jul 17, 2013 2:54 pm
by Anuj Dhawan
As Robert has said, there are multiple ways of doing it. Keeping the latest post from you in mind - one of follwoing should help you:
Code: Select all
//STEP010 EXEC PGM=ICETOOL
//TOOLMSG DD SYSOUT=*
//DFSMSG DD SYSOUT=*
//DD01 DD DSN=TAPE_FILE_NAME,
// DISP=SHR
//TOOLIN DD *
COUNT FROM(DD01)
/*
//*
Check DFSMSG for DD01, in S.ST.
You can alos use this code, this is rather straight and can be used directly in an Application where (merely) the reocrd count might be of interest. As the LENGTH=4 is specified in SYSIN, this can be used for input records=9999, you can amend it accordingly :
Code: Select all
//STEP010 EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SORTIN DD DSN=your.file.name,
// DISP=SHR
//SYSIN DD *
OPTION COPY
OUTFIL NODETAIL,REMOVECC,
TRAILER1=(COUNT=(M11,LENGTH=4))
/*
//SORTOUT DD SYSOUT=*
//*
Hope this helps.
Re: How to count No. of Records in Dataset using Sort?
Posted: Thu Aug 01, 2013 11:47 am
by harish123
Thank you Anuj. This is very useful. I don't need this for some production requirement but to make my daily work life easy.
Thanks again.
Re: How to count No. of Records in Dataset using Sort?
Posted: Tue Aug 20, 2013 6:05 pm
by Anuj Dhawan
Glad you find it helpful...

Re: How to count No. of Records in Dataset using Sort?
Posted: Mon Sep 23, 2013 9:25 am
by BobThomas
Robert Sample wrote:If the data set has about 2 billion records, I would NOT recommend using REXX.
Thanks - that make sense.