Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Sort: Number of Unique records from the input file to output

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> JCL & VSAM
View previous topic :: :: View next topic  
Author Message
TS70363

New User


Joined: 07 Apr 2010
Posts: 93
Location: Bangalore, India

PostPosted: Sat Mar 31, 2012 4:00 pm    Post subject: Sort: Number of Unique records from the input file to output
Reply with quote

Hi,

Input file: LRECL=8

I have registration numbers in position 1 to 8 in the input file. The registration numbers are repetitive.

Hence I want the count of number of occurrence of each registration number in the output file.

For this I am using the below Control Card

Code:

SORT FIELDS=(1,8,CH,A)
OUTFIL REMOVECC, NODETAIL,
SECTIONS=(1,8,
     TRAILER3=(11,10,COUNT=(M11,LENGTH(10))
/*


So I will get Registration number in 1 to 8 positions and the count of occurrence of those registration numbers in 11 to 20 positions.

No I also want the count of unique records written in the output file at the end of the report.

I have tried using 2 steps - in 1st step get the counts for each registration number and in 2nd step get the count of records written to output file

How do I achieve this in 1 step??
Back to top
View user's profile Send private message

Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7225

PostPosted: Sat Mar 31, 2012 4:16 pm    Post subject: Reply to: Sort: Number of Unique records from the input file
Reply with quote

Can you show the second step as well?

Can you confirm/deny that the space before ",DETAIL" is a typo - asis, it is a comment.

If a typo, please don't type, put paste. Pastos are much less common (though possible, done them myself :-) )
Back to top
View user's profile Send private message
saiprasadh

Active User


Joined: 20 Sep 2006
Posts: 154
Location: US

PostPosted: Sat Mar 31, 2012 11:43 pm    Post subject:
Reply with quote

Below sort card will work for your requirement.

Code:
//STEP010  EXEC PGM=ICETOOL                                           
//TOOLMSG  DD  SYSOUT=*                                               
//DFSMSG   DD  SYSOUT=*                                               
//INPUT1   DD  *                                                     
12345678                                                             
12345678                                                             
12345678                                                             
12345679                                                             
12345679                                                             
12345679                                                             
12345679                                                             
12345670                                                             
12345670                                                             
12345670                                                             
12345670                                                             
12345670                                                             
12345670                                                             
//TEMP1    DD  DSN=&&TEMP1,                                           
//             UNIT=(SYSDA,9),SPACE=(CYL,(25,50),RLSE),               
//             DISP=(MOD,DELETE,DELETE)                               
//OUTPUT   DD  SYSOUT=*                                             
//TOOLIN   DD *                                                     
   COPY FROM(INPUT1) TO(TEMP1) USING(CTL1)                         
   COPY FROM(TEMP1) TO(OUTPUT) USING(CTL2)                         
//CTL1CNTL DD *                                                     
 SORT FIELDS=(1,8,CH,A)                                             
 OUTFIL REMOVECC,NODETAIL,                                         
 SECTIONS=(1,8,                                                     
      TRAILER3=(1:1,8,9:2X,11,10,COUNT=(M11,LENGTH(10))))           
//CTL2CNTL DD *                                                     
 SORT FIELDS=(1,8,CH,A)                                             
 OUTFIL REMOVECC,                                                   
 TRAILER1=(1:C'UNIQUE RECORD COUNT:',21:COUNT=(M11,LENGTH=10))     
/*                                                                 


Output:

Code:
12345670            0000000006       
12345678            0000000003       
12345679            0000000004       
UNIQUE RECORD COUNT:0000000003       
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7225

PostPosted: Sun Apr 01, 2012 5:42 am    Post subject: Reply to: Sort: Number of Unique records from the input file
Reply with quote

With DFSORT using GROUP and KEYBEGIN, ID, TRAILER1 and MAX.

Defines a GROUP on change of key (1,8) value. Appends a 10-digit ID (starting from one, going up by one for each new "group").

The SECTIONS processing is what you have.

TRAILER1 has been added, which uses the MAXimum value of the appended ID for each group, representing the total number of groups (being the highest ID allocated), which is equal to the total number of unique keys.

The data can be SORTed on the key, if non-contiguous keys, or output data is required in sorted order.

If keys are contiguous and data is required in original order, the COPY can be used for the same results, as far as the all the counts are concerned.

NB. With the COPY, there is no need for the MAX, as the highest group ID will be that on the final data record, so could be replaced by
Code:
 TRAILER1=(1:C'COUNT OF UNIQUE KEYS:',9,10),

which will copy column 9 for length of 10 from the final data record, being the position of the ID.

Code:

//GROUPKEY EXEC PGM=SORT
//SYSOUT   DD SYSOUT=*
//SORTOUT  DD SYSOUT=*
//SYSIN    DD *
* SORT FIELDS=(1,8,CH,A)
  SORT FIELDS=COPY
  INREC IFTHEN=(WHEN=GROUP,KEYBEGIN=(1,8),PUSH=(9:ID=10))
  OUTFIL REMOVECC,NODETAIL,
      TRAILER1=(1:C'COUNT OF UNIQUE KEYS:',MAX=(9,10,ZD,M11)),
  SECTIONS=(1,8,
     TRAILER3=(1,8,X,COUNT=(M11,LENGTH(10))))
//*
//SORTIN   DD *
12345671
12345678
12345678
12345678
12345679
12345679
12345679
12345679
12345668
12345666
12345662
12345670
12345670
12345670
12345670
12345670
12345670


The output:

Code:
12345671 0000000001           
12345678 0000000003           
12345679 0000000004           
12345668 0000000001           
12345666 0000000001           
12345662 0000000001           
12345670 0000000006           
COUNT OF UNIQUE KEYS:0000000007


This sort deck works for me for your requirement (lightly tested). Since I don't know what product or level of product you have, I can't say if it is any use to you.
Back to top
View user's profile Send private message
saiprasadh

Active User


Joined: 20 Sep 2006
Posts: 154
Location: US

PostPosted: Sun Apr 01, 2012 11:39 pm    Post subject:
Reply with quote

Hi Bill,

For below mentioned input the sort card is providing wrong output

Input:

Code:
12345678   
12345678   
12345678   
12345679   
12345679   
12345679   
12345679   
12345670   
12345670   
12345670   
12345670   
12345670   
12345670   
12345678   
12345678   
12345678   



Output:


Code:
12345670 0000000006             
12345678 0000000006             
12345679 0000000004             
COUNT OF UNIQUE KEYS:0000000004 
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7225

PostPosted: Mon Apr 02, 2012 12:26 am    Post subject: Reply to: Sort: Number of Unique records from the input file
Reply with quote

Thanks Sai. My bad.

Change the INREC to OUTREC.
Back to top
View user's profile Send private message
TS70363

New User


Joined: 07 Apr 2010
Posts: 93
Location: Bangalore, India

PostPosted: Mon Apr 02, 2012 1:39 pm    Post subject: Reply to: Sort: Number of Unique records from the input file
Reply with quote

Hi,

The sort card is valid for DFSORT but we using SYNCSORT.

Could you please help me revise the sort card.
Back to top
View user's profile Send private message
xknight

Active User


Joined: 22 Jan 2008
Posts: 117
Location: Liberty city

PostPosted: Mon Apr 02, 2012 1:59 pm    Post subject:
Reply with quote

Hello,

Did you tried submitting the job?

Post your sysout messages.
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7225

PostPosted: Mon Apr 02, 2012 2:02 pm    Post subject: Reply to: Sort: Number of Unique records from the input file
Reply with quote

Toss either or both sort decks into Syncsort (not at the same time).

Analyse the errors thrown back at you with the aid of your manual.

"Fix up" the syntax if possible, or peruse the manual to find an alternative.

Oh, I was forgetting. You already have a second step, which you were asked to show earlier, don't you?
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> JCL & VSAM All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts High CPU consumption Job using IAM fi... aswinir JCL & VSAM 8 Thu Dec 01, 2016 8:28 pm
No new posts Add PD field from 2nd file to PD in 1st Sushant Garje DFSORT/ICETOOL 6 Thu Dec 01, 2016 4:32 pm
No new posts File Aid to File Manager conversion murali3955 IBM Tools 4 Thu Nov 24, 2016 3:41 pm
No new posts Limit duplicate records in the SORT pshongal SYNCSORT 6 Mon Nov 21, 2016 12:54 pm
No new posts How to convert the VBM file to VB or... Sulabh Agrawal JCL & VSAM 4 Fri Nov 18, 2016 1:04 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us