Count the number of records in a Dataset using REXX.

Time Sharing Option, Interactive System Productivity Facility and REstructured eXtended eXecutor

Moderator: mickeydusaor

Post Reply
Shahid
Registered Member
Posts: 47
Joined: Sun Aug 25, 2013 1:00 am

Count the number of records in a Dataset using REXX.

Post 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?
enrico-sorichetti
Global Moderator
Global Moderator
Posts: 824
Joined: Wed Sep 11, 2013 3:57 pm

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

Post by enrico-sorichetti »

investigate the use of ICETOOOL and the COUNT command
cheers
enrico
When I tell somebody to RTFM or STFW I usually have the page open in another tab/window of my browser,
so that I am sure that the information requested can be reached with a very small effort 8-)
William Collins
Global Moderator
Global Moderator
Posts: 490
Joined: Sun Aug 25, 2013 7:24 pm

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

Post 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.
Shahid
Registered Member
Posts: 47
Joined: Sun Aug 25, 2013 1:00 am

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

Post 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.
enrico-sorichetti
Global Moderator
Global Moderator
Posts: 824
Joined: Wed Sep 11, 2013 3:57 pm

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

Post 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.
cheers
enrico
When I tell somebody to RTFM or STFW I usually have the page open in another tab/window of my browser,
so that I am sure that the information requested can be reached with a very small effort 8-)
User avatar
Anuj Dhawan
Founder
Posts: 2799
Joined: Sun Apr 21, 2013 7:40 pm
Location: Mumbai, India
Contact:
India

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

Post 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.
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
Akatsukami
Global Moderator
Global Moderator
Posts: 122
Joined: Tue Oct 20, 2015 3:20 am
Location: Bloomington, IL
Contact:

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

Post 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.
"I come to the conclusion that, men loving according to their own will and fearing according to that of the prince, a wise prince should establish himself on that which is in his own control and not in that of others." -- Niccolò Machiavelli
enrico-sorichetti
Global Moderator
Global Moderator
Posts: 824
Joined: Wed Sep 11, 2013 3:57 pm

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

Post 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
cheers
enrico
When I tell somebody to RTFM or STFW I usually have the page open in another tab/window of my browser,
so that I am sure that the information requested can be reached with a very small effort 8-)
Shahid
Registered Member
Posts: 47
Joined: Sun Aug 25, 2013 1:00 am

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

Post 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?
nicc
Global Moderator
Global Moderator
Posts: 691
Joined: Wed Apr 23, 2014 8:45 pm

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

Post 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).
Regards
Nic
Shahid
Registered Member
Posts: 47
Joined: Sun Aug 25, 2013 1:00 am

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

Post 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?
Shahid
Registered Member
Posts: 47
Joined: Sun Aug 25, 2013 1:00 am

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

Post by Shahid »

enrico-sorichetti wrote: investigate the use of ICETOOOL and the COUNT command
Will using ICETOOL helps compared to REXX?
nicc
Global Moderator
Global Moderator
Posts: 691
Joined: Wed Apr 23, 2014 8:45 pm

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

Post 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.
Regards
Nic
nicc
Global Moderator
Global Moderator
Posts: 691
Joined: Wed Apr 23, 2014 8:45 pm

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

Post by nicc »

Will using ICETOOL helps compared to REXX?
Why not try to be professional and run a test or two of your own?
Regards
Nic
zprogrammer
Global Moderator
Global Moderator
Posts: 588
Joined: Wed Nov 20, 2013 11:53 am
Location: Mars

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

Post by zprogrammer »

As Enrico said REXX is not powerful to handle huge amount of records,

Why not use OUTFIL + TRAILER + COUNT through DFSORT ?
zprogrammer
Shahid
Registered Member
Posts: 47
Joined: Sun Aug 25, 2013 1:00 am

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

Post 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 
/* 
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 “TSO, ISPF & REXX (Do you still do CLIST?!).”