Once a colleague asked me about the fastest way to count the number of records in a dataset. My first answer was to browse the dataset and execute a FIND P'=' 1 ALL. The number of records is then displayed in the upper right corner of the ISPF panel after a period of time depending on the size of the member or dataset.
Unfortunately this simple solution is not very fast if the dataset is quite large and on top of this the ISPF browser has a hard time with VSAM datasets. I had to come up with another idea. After some thinking I remembered that DFSORT reports the number of records read from the input dataset. On the other hand you have to use SYSIN in order to tell DFSORT whether it must sort or copy the input data and I did not want to use SYSIN. Many installations chooses to replace the original IEBGENER with the DFSORT equivalent called ICEGENER. Therefore I made the following job step:
On your installation you may use IEBGENER instead of ICEGENER and maybe you must use //SYSPRINT instead of //SYSOUT. As the step does not need to copy anything you might as well specify SYSUT2 as DUMMY. You do not need to specify SYSIN because the default action for ICEGENER/IEBGENER is to copy from SYSUT1 to SYSUT2. On SYSOUT=* you will find a lot of information about DFSORT processing and the interesting part is in one of the last lines prefixed with message-id ICE054I and looks like this:
where <number of records> is replaced with the actual number of records in MY.BIG.DATASET or whatever the name of your dataset is. If MY.BIG.DATASET is a PDS (member dataset) the step will fail, because you need to specify a member in parenthesis after the dataset name. On the other hand the step is able to count the number of records in VSAM datasets. The most important part is the speed of the step which is very fast. If you want to use a command in your TSO session you can easily create a REXX to do the job. The REXX must allocate the DD names in the job step and then execute ICEGENER using an ADDRESS TSO "ICEGENER". The hard part is to find ICE054I in the output and display it to the user in a friendly way.
If you know about other ways of counting records which are even faster than mentioned here I would like to hear from you. I think there must be a faster tool out there because ICEGENER uses time on writing records to the DUMMY dataset.