View previous topic :: View next topic
Author
Message
TS70363 New User Joined: 07 Apr 2010Posts: 94 Location: Bangalore, India
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
Bill Woodger Moderator Emeritus Joined: 09 Mar 2011Posts: 7309 Location: Inside the Matrix
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
saiprasadh Active User Joined: 20 Sep 2006Posts: 154 Location: US
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
Bill Woodger Moderator Emeritus Joined: 09 Mar 2011Posts: 7309 Location: Inside the Matrix
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
saiprasadh Active User Joined: 20 Sep 2006Posts: 154 Location: US
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
Bill Woodger Moderator Emeritus Joined: 09 Mar 2011Posts: 7309 Location: Inside the Matrix
Thanks Sai. My bad.
Change the INREC to OUTREC.
Back to top
TS70363 New User Joined: 07 Apr 2010Posts: 94 Location: Bangalore, India
Hi,
The sort card is valid for DFSORT but we using SYNCSORT.
Could you please help me revise the sort card.
Back to top
xknight Active User Joined: 22 Jan 2008Posts: 117 Location: Liberty city
Hello,
Did you tried submitting the job?
Post your sysout messages.
Back to top
Bill Woodger Moderator Emeritus Joined: 09 Mar 2011Posts: 7309 Location: Inside the Matrix
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
Please enable JavaScript!