IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

How can we count the number of records in a dataset?


IBM Mainframe Forums -> JCL & VSAM
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
gauravjha

New User


Joined: 16 Apr 2005
Posts: 1

PostPosted: Mon Apr 18, 2005 2:15 pm
Reply with quote

What are the possible ways to know the number of records in a data set( PS or VSAM)?
Back to top
View user's profile Send private message
andycool

New User


Joined: 12 Apr 2005
Posts: 64

PostPosted: Mon Apr 18, 2005 8:05 pm
Reply with quote

Write a pgm which will do the following things:

1. Read the input file.
2. Set a counter to 0.
3. On every "Read" statement increment the counter UNTIL End Of File.
4. Display the counter in SYSOUT.

JCL step for this:

//stepname exec pgm=program
//input dd dsn=input_dataset
//sysout dd sysout=*
//
Back to top
View user's profile Send private message
somasundaran_k

Active User


Joined: 03 Jun 2003
Posts: 134

PostPosted: Mon Apr 18, 2005 8:14 pm
Reply with quote

If you want to use any utilities try Fileaid or Sort to find the record count.

hth
-Som
Back to top
View user's profile Send private message
superk

Global Moderator


Joined: 26 Apr 2004
Posts: 4652
Location: Raleigh, NC, USA

PostPosted: Mon Apr 18, 2005 8:47 pm
Reply with quote

The easiest way is to use DFSORT:
Code:

//*                                                 
//COUNT EXEC PGM=ICETOOL                         
//TOOLMSG  DD   SYSOUT=*                           
//DFSMSG   DD   SYSOUT=*                           
//IN       DD   DSN=MY.DATASET,DISP=SHR
//TOOLIN   DD   DATA                               
  COUNT FROM(IN)                                   
/*                                                 
//*

Or, to place the record count into an output dataset:
Code:
                                           
//COUNT EXEC PGM=SORT                             
//SORTIN   DD   DSN=MY.DATASET,DISP=SHR           
//SYSOUT   DD   SYSOUT=*                             
//SORTOUT  DD  DSN=MY.OUTPUT.DSN,DISP=(,CATLG,DELETE),...                             
//SYSIN    DD   DATA                                 
  OPTION COPY                                         
  OUTFIL REMOVECC,NODETAIL,                           
    SECTIONS=(1,2,                                   
      TRAILER3=(1:COUNT=(M10,LENGTH=10)))             
/*         
Back to top
View user's profile Send private message
andycool

New User


Joined: 12 Apr 2005
Posts: 64

PostPosted: Mon Apr 18, 2005 9:00 pm
Reply with quote

Right !
This is where experience stands out.
Appreciations SuperK
Back to top
View user's profile Send private message
Frank Yaeger

DFSORT Developer


Joined: 15 Feb 2005
Posts: 7129
Location: San Jose, CA

PostPosted: Mon Apr 18, 2005 9:25 pm
Reply with quote

Superk,

Your second DFSORT job should be:

Code:

//COUNT EXEC PGM=SORT
//SORTIN   DD   DSN=MY.DATASET,DISP=SHR
//SYSOUT   DD   SYSOUT=*
//SORTOUT  DD  DSN=MY.OUTPUT.DSN,DISP=(,CATLG,DELETE),...
//SYSIN    DD   DATA
  OPTION COPY
  OUTFIL REMOVECC,NODETAIL,
    TRAILER1=(COUNT=(M10,LENGTH=10))
/*


TRAILER1 will give a single record with the count. It doesn't make sense to use SECTIONS/TRAILER3 in this case, since that would give a count for each value in positions 1-2.
Back to top
View user's profile Send private message
die7nadal

Active User


Joined: 23 Mar 2005
Posts: 156

PostPosted: Tue Apr 19, 2005 12:43 am
Reply with quote

Frank Yaeger wrote:
Superk,

Your second DFSORT job should be:

Code:

//COUNT EXEC PGM=SORT
//SORTIN   DD   DSN=MY.DATASET,DISP=SHR
//SYSOUT   DD   SYSOUT=*
//SORTOUT  DD  DSN=MY.OUTPUT.DSN,DISP=(,CATLG,DELETE),...
//SYSIN    DD   DATA
  OPTION COPY
  OUTFIL REMOVECC,NODETAIL,
    TRAILER1=(COUNT=(M10,LENGTH=10))
/*


TRAILER1 will give a single record with the count. It doesn't make sense to use SECTIONS/TRAILER3 in this case, since that would give a count for each value in positions 1-2.



1) I have a file with a HEADER REC and a TRAILER REC and the Trailer will contain the Total count of the records in a particular position excluding the Header and Trailer
2) Now I take the File and strip some records for testing purposes, But the Trailer count wont tally
3) I want to tally the total number of records and the position of the Total count wont be same for all the files.
4) Is there anyway I can do the tallying of the recs using SYNCSORT.
Back to top
View user's profile Send private message
superk

Global Moderator


Joined: 26 Apr 2004
Posts: 4652
Location: Raleigh, NC, USA

PostPosted: Tue Apr 19, 2005 12:57 am
Reply with quote

Thanks. I think I posted the example code from a job that actually did give a count for each value.
Back to top
View user's profile Send private message
Frank Yaeger

DFSORT Developer


Joined: 15 Feb 2005
Posts: 7129
Location: San Jose, CA

PostPosted: Tue Apr 19, 2005 1:25 am
Reply with quote

die7nadal,

FYI, I'm happy to answer questions on DFSORT and DFSORT's ICETOOL, but I don't answer questions on Syncsort.
Back to top
View user's profile Send private message
die7nadal

Active User


Joined: 23 Mar 2005
Posts: 156

PostPosted: Tue Apr 19, 2005 1:40 am
Reply with quote

Frank Yaeger wrote:
die7nadal,

FYI, I'm happy to answer questions on DFSORT and DFSORT's ICETOOL, but I don't answer questions on Syncsort.


Okie frank, make it in DFSORT.
Back to top
View user's profile Send private message
Frank Yaeger

DFSORT Developer


Joined: 15 Feb 2005
Posts: 7129
Location: San Jose, CA

PostPosted: Tue Apr 19, 2005 3:19 am
Reply with quote

Quote:
Okie frank, make it in DFSORT.


Let me rephrase that: I'm happy to answer questions for customers who are using DFSORT, but I don't answer questions for customers who aren't using DFSORT.

You said you were using Syncsort. Do you have DFSORT as well?
Back to top
View user's profile Send private message
die7nadal

Active User


Joined: 23 Mar 2005
Posts: 156

PostPosted: Tue Apr 19, 2005 9:34 am
Reply with quote

yeah I have DFSORT in my installation now.
Back to top
View user's profile Send private message
Frank Yaeger

DFSORT Developer


Joined: 15 Feb 2005
Posts: 7129
Location: San Jose, CA

PostPosted: Tue Apr 19, 2005 8:16 pm
Reply with quote

Ok, then please show an example of your input records and what you want the output records to look like. Also, what is the RECFM and LRECL of the input file.
Back to top
View user's profile Send private message
die7nadal

Active User


Joined: 23 Mar 2005
Posts: 156

PostPosted: Tue Apr 19, 2005 9:13 pm
Reply with quote

The recs look like below
Code:
********************************* Top of Data ***********
CNTL  0150400002        000001                           
00204505000039620E001S2911116    631               620207
00204481335000020103614633034    995               881020
0010 481335000020100014633034    995               881020
00204481335000020103623333033    996               881020
0010 481335000020100023333033    996               881020
00204481335000010102223479999    968               880810
00201481335000010199923479999    968               880810
00201481335000010199923479999    968               880810
00204481335000010102229275600    969               880810
00202481335000010199929275600    969               880810
00202481335000010199929275600    969               880810
TRLR  0150400002  000000000013                           
******************************** Bottom of Data *********


There will be only one Header CNTL rec and one Trailer TRLR Rec. The Trailer will contain the total count of the records exclusive of CNTL, TRLR rec in a particular position. Now if I strip certain recs I need to automatically tally the total no. of recs at the TRLR rec. Should I necessarily give the position of the Total recs count in TRLR rec, becos I have a number of similar files where the position of Total recs count may not be same in the above file it starts from 19 is 12 cols long. If u need some more info please lemme know.
Back to top
View user's profile Send private message
die7nadal

Active User


Joined: 23 Mar 2005
Posts: 156

PostPosted: Tue Apr 19, 2005 9:19 pm
Reply with quote

The RECFM is VB and the LRECL is 57.
Back to top
View user's profile Send private message
Frank Yaeger

DFSORT Developer


Joined: 15 Feb 2005
Posts: 7129
Location: San Jose, CA

PostPosted: Wed Apr 20, 2005 12:53 am
Reply with quote

Can you recreate the TRLR record, that is, rebuild it on the fly with the information you need in it, or do you have to merge the new count into the existing trailer record? It looks like the trailer record only has three fields: 'TRLR' is a constant so it can be rebuilt on the fly. The count-2 can be rebuilt on the fly. So the question is can the 0150400002 field be rebuilt on the fly - is it always going to be 0150400002, or something else that can be built (e.g. the run date), or does it have to be saved from the trailer record and put back into it?

Quote:
Should I necessarily give the position of the Total recs count in TRLR rec, becos I have a number of similar files where the position of Total recs count may not be same in the above file it starts from 19 is 12 cols long.


Are you saying that the count may be in different places in the trailer record for different input files? If so, what is it you want to know about that?
Back to top
View user's profile Send private message
die7nadal

Active User


Joined: 23 Mar 2005
Posts: 156

PostPosted: Wed Apr 20, 2005 1:25 am
Reply with quote

I cannot recreate the TRLR record, I just want to update the Record count in trailer Or it can be saved from the trailer rec and put back.
I wanted to know if I have to give the position of the count in the Control Card or if It can find by itself, bcos I have different File where the position of Recs count may vary Or in other words I wont know the position of the record Count.
Back to top
View user's profile Send private message
Frank Yaeger

DFSORT Developer


Joined: 15 Feb 2005
Posts: 7129
Location: San Jose, CA

PostPosted: Wed Apr 20, 2005 3:09 am
Reply with quote

Here's a DFSORT/ICETOOL job that will give you what you want. You will have to change the job for different count locations, but I've used DFSORT Symbols to make that easier. Just map different records with the appropriate symbols.

You'll also need z/OS DFSORT V1R5 PTF UQ95214 or DFSORT R14 PTF UQ95213 (Dec, 2004) to use DFSORT's new COUNT-n and IFTHEN functions. If you have DFSORT, but you don't have the Dec, 2004 PTF, ask your System Programmer to install it.

Code:

//S1    EXEC  PGM=ICETOOL
//SYMNAMES DD *
*TRAILER RECORD SYMBOLS
* |RDW|'TRLR'|KEEP|count|
RDW,1,4        RDW
ID,*,4,CH      'TRLR' location
KEEP,*,14      Length of bytes between 'TRLR' and count
TRLID,'TRLR'   'TRLR' id
DELID,'TTTT'   'TTTT' id
/*
//TOOLMSG   DD  SYSOUT=*
//DFSMSG   DD  SYSOUT=*
//IN DD DSN=...  input file (VB)
//T1 DD DSN=&&T1,UNIT=SYSDA,SPACE=(CYL,(5,5)),DISP=(,PASS)
//OUT DD DSN=...  output file (VB)
//TOOLIN   DD    *
  COPY FROM(IN) USING(CTL1)
  COPY FROM(T1) TO(OUT) USING(CTL2)
/*
//CTL1CNTL DD *
* Change 'TRLR' in the original trailer record to 'TTTT'.
  INREC IFTHEN=(WHEN=(ID,EQ,C'TRLR'),OVERLAY=(5:DELID))
* Create a new trailer record with 'TRLR', the data from the
* original trailer record and a count of the data records
* (total input records - 2).
* T1 will have the header record, the data records, the
* 'TTTT' record and the new 'TRLR' record.
  OUTFIL FNAMES=T1,REMOVECC,
    TRAILER1=(TRLID,KEEP,COUNT-2=(M11,LENGTH=12))
/*
//CTL2CNTL DD *
* Remove the 'TTTT' record.
  OMIT COND=(ID,EQ,DELID)
/*
Back to top
View user's profile Send private message
die7nadal

Active User


Joined: 23 Mar 2005
Posts: 156

PostPosted: Wed Apr 20, 2005 7:00 am
Reply with quote

Thanks Frank
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> JCL & VSAM

 


Similar Topics
Topic Forum Replies
No new posts To get the count of rows for every 1 ... DB2 3
No new posts FINDREP - Only first record from give... DFSORT/ICETOOL 3
No new posts Compare only first records of the fil... SYNCSORT 7
No new posts Pulling a fixed number of records fro... DB2 2
No new posts Substring number between 2 characters... DFSORT/ICETOOL 2
Search our Forums:

Back to Top