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

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


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

New User


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

PostPosted: Sat Mar 31, 2012 4:00 pm
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

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Sat Mar 31, 2012 4:16 pm
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
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

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Sun Apr 01, 2012 5:42 am
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
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

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Mon Apr 02, 2012 12:26 am
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: 94
Location: Bangalore, India

PostPosted: Mon Apr 02, 2012 1:39 pm
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
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

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Mon Apr 02, 2012 2:02 pm
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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> JCL & VSAM

 


Similar Topics
Topic Forum Replies
No new posts Binary File format getting change whi... All Other Mainframe Topics 7
No new posts How to turn off 'ACTION' SDSF output ... TSO/ISPF 2
No new posts To fetch records that has Ttamp value... DFSORT/ICETOOL 4
No new posts ICETOOL returns no records JCL & VSAM 1
No new posts Compare 2 files and retrive records f... DFSORT/ICETOOL 3
Search our Forums:

Back to Top