Count the number of records in a Dataset using REXX.

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

Moderator: mickeydusaor


Topic author
Shahid
Registered Member
Posts: 40
Joined: Sun Aug 25, 2013 1:00 am
Has thanked: 12 times

Count the number of records in a Dataset using REXX.

Postby Shahid » Tue Dec 15, 2015 9:47 pm

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: 822
Joined: Wed Sep 11, 2013 3:57 pm
Been thanked: 69 times

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

Postby enrico-sorichetti » Tue Dec 15, 2015 11:06 pm

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: 499
Joined: Sun Aug 25, 2013 7:24 pm
Has thanked: 1 time
Been thanked: 25 times

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

Postby William Collins » Wed Dec 16, 2015 12:55 pm

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.




Topic author
Shahid
Registered Member
Posts: 40
Joined: Sun Aug 25, 2013 1:00 am
Has thanked: 12 times

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

Postby Shahid » Wed Dec 16, 2015 5:24 pm

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: 822
Joined: Wed Sep 11, 2013 3:57 pm
Been thanked: 69 times

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

Postby enrico-sorichetti » Wed Dec 16, 2015 5:27 pm

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: 2392
Joined: Sun Apr 21, 2013 7:40 pm
Location: Mumbai, India
Has thanked: 152 times
Been thanked: 66 times

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

Postby Anuj Dhawan » Wed Dec 16, 2015 8:30 pm

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

User avatar

Akatsukami
Global Moderator
Global Moderator
Posts: 105
Joined: Tue Oct 20, 2015 3:20 am
Location: Bloomington, IL
Has thanked: 2 times
Been thanked: 14 times

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

Postby Akatsukami » Wed Dec 16, 2015 8:33 pm

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: 822
Joined: Wed Sep 11, 2013 3:57 pm
Been thanked: 69 times

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

Postby enrico-sorichetti » Wed Dec 16, 2015 10:30 pm

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-)


Topic author
Shahid
Registered Member
Posts: 40
Joined: Sun Aug 25, 2013 1:00 am
Has thanked: 12 times

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

Postby Shahid » Fri Dec 18, 2015 3:18 pm

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: 544
Joined: Wed Apr 23, 2014 8:45 pm
Been thanked: 11 times

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

Postby nicc » Fri Dec 18, 2015 5:09 pm

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


Topic author
Shahid
Registered Member
Posts: 40
Joined: Sun Aug 25, 2013 1:00 am
Has thanked: 12 times

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

Postby Shahid » Mon Aug 08, 2016 1:42 pm

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?




Topic author
Shahid
Registered Member
Posts: 40
Joined: Sun Aug 25, 2013 1:00 am
Has thanked: 12 times

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

Postby Shahid » Mon Aug 08, 2016 1:50 pm

enrico-sorichetti wrote:Source of the post investigate the use of ICETOOOL and the COUNT command


Will using ICETOOL helps compared to REXX?




nicc
Global Moderator
Global Moderator
Posts: 544
Joined: Wed Apr 23, 2014 8:45 pm
Been thanked: 11 times

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

Postby nicc » Mon Aug 08, 2016 8:12 pm

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: 544
Joined: Wed Apr 23, 2014 8:45 pm
Been thanked: 11 times

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

Postby nicc » Mon Aug 08, 2016 8:13 pm

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: 603
Joined: Wed Nov 20, 2013 11:53 am
Location: Mars
Has thanked: 7 times
Been thanked: 7 times

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

Postby zprogrammer » Mon Aug 08, 2016 9:27 pm

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

Why not use OUTFIL + TRAILER + COUNT through DFSORT ?


zprogrammer


Topic author
Shahid
Registered Member
Posts: 40
Joined: Sun Aug 25, 2013 1:00 am
Has thanked: 12 times

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

Postby Shahid » Thu Aug 11, 2016 12:28 pm

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
/*




Return to “TSO, ISPF & REXX (Do you still do CLIST?!).”

Who is online

Users browsing this forum: CommonCrawl [Bot] and 0 guests