Page 1 of 1

Count the number of records in a Dataset using REXX.

Posted: Tue Dec 15, 2015 9:47 pm
by Shahid
Hi,

Where I worked previously, they used to have a line command named "count". If you go to ISPF 3.4, locate the dataset and adjacent to it if we issue COUNT, it'll show you the number of records in the dataset. Now I realize it was probably a REXX written there. How can we create a REXX which can Count the number of records in a Dataset?

Re: Count the number of records in a Dataset using REXX.

Posted: Tue Dec 15, 2015 11:06 pm
by enrico-sorichetti
investigate the use of ICETOOOL and the COUNT command

Re: Count the number of records in a Dataset using REXX.

Posted: Wed Dec 16, 2015 12:55 pm
by William Collins
A panel to allow a count of the number of records on a dataset? What a waste of resources. You know that someone (likely) pays for resource-usage on the Mainframe?

If you want to find out the number of records, don't lose them. Maintain them on a trailer/stats record, and reconcile them each time the dataset is read sequentially in full. Produce counts of input vs output and reconciling items at the end, and abend if discrepancies come to light.

Shoot the author of the panel.

Re: Count the number of records in a Dataset using REXX.

Posted: Wed Dec 16, 2015 5:24 pm
by Shahid
I did not make it clear. COUNT was a line command. Once the data-set name is located in ISPF 3.4, adjacent to COUNT will written and enter. That gave the number of records. No panel was called.

Re: Count the number of records in a Dataset using REXX.

Posted: Wed Dec 16, 2015 5:27 pm
by enrico-sorichetti
I did not make it clear. COUNT was a line command. Once the data-set name is located in ISPF 3.4, adjacent to COUNT will written and enter. That gave the number of records. No panel was called.
You are splitting hairs

to write something to count records and count records outside an application program is just a waste of resources

if Your applications need record count auditing , proper trailer processing should be put in place.

Re: Count the number of records in a Dataset using REXX.

Posted: Wed Dec 16, 2015 8:30 pm
by Anuj Dhawan
I think I get what are you asking. Perhaps because one of clients I worked for back in 2005 had such a tool in place. But for large files the use of REXX to count the number of records is overkill. You should listen to Enrico's advice. Having said that, try this REXX snippet from an old reference:

Code: Select all

/* REXX COUNT */
ARG DSN  .
IF DSN = "" THEN SIGNAL EXIOS

SYSDSORG = ""
CALL LISTDSI DSN "DIRECTORY" "RECALL"

IF SYSDSORG = "PS" THEN DO
  NAME_TO_COUNT = TRANSLATE(DSN," ","'")
  NAME_TO_COUNT = SPACE(NAME_TO_COUNT,0)
  "ALLOC DSN(*) DDN(SYSPRINT) REUSE"
  "ALLOC DDN(INFILE) SHR REUSE DSN("DSN")"
  "ALLOC DUMMY DDN(OUTFILE) REUSE  BLKSIZE(32000)"


  CALL OUTTRAP "SYSPRINT." , "*"

  "REPRO INFILE(INFILE) OUTFILE(OUTFILE) "
  CALL OUTTRAP "OFF"

  DO I = 1 TO SYSPRINT.0
    /*SAY SYSPRINT.I*/
    PARSE VAR SYSPRINT.I "WAS" RECORD_COUNT
    IF DATATYPE(RECORD_COUNT) = "NUM" THEN LEAVE
  END I

  IF DATATYPE(SYSLRECL) = "NUM" THEN DO
     SAY "RECORD COUNT  = " RECORD_COUNT
     SAY "RECORD LENGTH = " SYSLRECL
     SAY "BYTE COUNT    = " SYSLRECL * RECORD_COUNT
     END

  "ALLOC DDN(SYSIN) DSN(*) REUSE"
  "ALLOC DDN(SYSPRINT) DSN(*) REUSE"
  "FREE DDN(INFILE OUTFILE )"

  EXIT
  END /* FOR PS */

IF SYSDSORG = "PO" THEN DO
SAY SYSMEMBERS "MEMBERS IN PDS"
EXIT
END

IF SYSDSORG = "VS" THEN DO
SAY "CANNOT COUNT RECORDS IN VSAM DATASET"
EXIT
END

EXIOS:
SAY "COUNT WILL COUNT RECORDS IN A SEQUENTIAL FILE"
SAY "OR MEMBERS IN A PDS"
SAY "ANYTHING ELSE, CAN'T DO"
SAY "REEXECUTE. PUT COUNT TO LEFT OF DSNAME ON ISPF 3.4 DSLIST"
EXIT
Please note, this will work only from/in TSO and/or ISPF. If you issue it on a PDS, you'll get count for number of members in the PDS.

Re: Count the number of records in a Dataset using REXX.

Posted: Wed Dec 16, 2015 8:33 pm
by Akatsukami
You can easily write an exec fulfilling this requirement by reading the data set and incrementing a counter each time a record is read, then SAYing that counter at the end. Performance may range from adequate to unacceptable depending on the size of the data set.

Note that what Mr. Collins and Dr. Sorichetti are telling you is that this is an inferior solution to having properly designed programs; you ought to be able to determine the record count by browsing the trailer. We recognize that your words may have no weight in the design phase, but we senpai are usually reluctant to provide Band-aidsĀ® for self-inflicted wounds.

Re: Count the number of records in a Dataset using REXX.

Posted: Wed Dec 16, 2015 10:30 pm
by enrico-sorichetti
for the umpteenth time ...
using Rexx to read Huge amounts of records will usually result in abends and unreasonably long/large elapsed/cpu times. AMEN

we reply on our own time, free of charge and we share experience
we provide solutions according to out best judgement and best practices
if You want poor solutions based on poor requirements and poor analysis hire a paid consultant
who for the proper fee will give You the solutions You asked for

Re: Count the number of records in a Dataset using REXX.

Posted: Fri Dec 18, 2015 3:18 pm
by Shahid
Hi,

I agree that this will be a CPU intensive process for the large files. But for a test region it should be fine? Or there are some constraints in this region too?

Re: Count the number of records in a Dataset using REXX.

Posted: Fri Dec 18, 2015 5:09 pm
by nicc
Why should unneccessary CPU-intensive processing of large datasets (not files) in a test region be acceptable? You will hinder the use of other developers/testers and be wasting resources. And, yes, there should be large datasets in the test region for stress testing (amongst other things).

Re: Count the number of records in a Dataset using REXX.

Posted: Mon Aug 08, 2016 1:42 pm
by Shahid
I agreee to all of you but why such a small thing is such a big deal in mainframes? On windows I have never heard people stopping you from doing it?

Re: Count the number of records in a Dataset using REXX.

Posted: Mon Aug 08, 2016 1:50 pm
by Shahid
enrico-sorichetti wrote: investigate the use of ICETOOOL and the COUNT command
Will using ICETOOL helps compared to REXX?

Re: Count the number of records in a Dataset using REXX.

Posted: Mon Aug 08, 2016 8:12 pm
by nicc
I agreee to all of you but why such a small thing is such a big deal in mainframes? On windows I have never heard people stopping you from doing it?
Because a mainframe is a shared system - you are one of maybe thousands of people using it at the same time - not to mention other tasks. A PC is a single user machine - you are only holding yourself up.

Re: Count the number of records in a Dataset using REXX.

Posted: Mon Aug 08, 2016 8:13 pm
by nicc
Will using ICETOOL helps compared to REXX?
Why not try to be professional and run a test or two of your own?

Re: Count the number of records in a Dataset using REXX.

Posted: Mon Aug 08, 2016 9:27 pm
by zprogrammer
As Enrico said REXX is not powerful to handle huge amount of records,

Why not use OUTFIL + TRAILER + COUNT through DFSORT ?

Re: Count the number of records in a Dataset using REXX.

Posted: Thu Aug 11, 2016 12:28 pm
by Shahid
I have tried the follwoing solutions but with 1000 records there is not much difference between CPU use. I shall use REXX as we do not have much records to cound for now. But it helps in small testing easilty.

With ICETOOL:

Code: Select all

//STEPCNT    EXEC PGM=ICETOOL                        
//TOOLMSG   DD SYSOUT=*                              
//DFSMSG    DD SYSOUT=*                              
//IN        DD DSN=MY.INPUT.DATASET, 
//             DISP=SHR                              
//TOOLIN    DD *                                    
  COUNT FROM(IN)                                    
/* 
With REXX:

Code: Select all

/* REXX COUNT */
ARG DSN  .
IF DSN = "" THEN SIGNAL EXIOS

SYSDSORG = ""
CALL LISTDSI DSN "DIRECTORY" "RECALL"

IF SYSDSORG = "PS" THEN DO
  NAME_TO_COUNT = TRANSLATE(DSN," ","'")
  NAME_TO_COUNT = SPACE(NAME_TO_COUNT,0)
  "ALLOC DSN(*) DDN(SYSPRINT) REUSE"
  "ALLOC DDN(INFILE) SHR REUSE DSN("DSN")"
  "ALLOC DUMMY DDN(OUTFILE) REUSE  BLKSIZE(32000)"


  CALL OUTTRAP "SYSPRINT." , "*"

  "REPRO INFILE(INFILE) OUTFILE(OUTFILE) "
  CALL OUTTRAP "OFF"

  DO I = 1 TO SYSPRINT.0
    /*SAY SYSPRINT.I*/
    PARSE VAR SYSPRINT.I "WAS" RECORD_COUNT
    IF DATATYPE(RECORD_COUNT) = "NUM" THEN LEAVE
  END I

  IF DATATYPE(SYSLRECL) = "NUM" THEN DO
     SAY "RECORD COUNT  = " RECORD_COUNT
     SAY "RECORD LENGTH = " SYSLRECL
     SAY "BYTE COUNT    = " SYSLRECL * RECORD_COUNT
     END

  "ALLOC DDN(SYSIN) DSN(*) REUSE"
  "ALLOC DDN(SYSPRINT) DSN(*) REUSE"
  "FREE DDN(INFILE OUTFILE )"

  EXIT
  END /* FOR PS */

IF SYSDSORG = "PO" THEN DO
SAY SYSMEMBERS "MEMBERS IN PDS"
EXIT
END

IF SYSDSORG = "VS" THEN DO
SAY "CANNOT COUNT RECORDS IN VSAM DATASET"
EXIT
END

EXIOS:
SAY "COUNT WILL COUNT RECORDS IN A SEQUENTIAL FILE"
SAY "OR MEMBERS IN A PDS"
SAY "ANYTHING ELSE, CAN'T DO"
SAY "REEXECUTE. PUT COUNT TO LEFT OF DSNAME ON ISPF 3.4 DSLIST"
EXIT
And Sort:

Code: Select all

//STEPCNT  EXEC  PGM=SORT                            
//SYSOUT  DD SYSOUT=*                              
//SORTIN  DD DSN=MY-INPUT-DATASET,                                      
//           DISP=SHR 
//SORTOUT DD DUMMY                                
//SYSIN   DD *                                  
 SORT FIELDS=COPY 
/*