Skolusu
Senior Member
Joined: 07 Dec 2007 Posts: 2205 Location: San Jose
|
|
|
|
Jemonthomas,
There are many ways to get the max dup record. The following are your control cards
Code: |
SORT FIELDS=(1,10,CH,A,11,4,BI,A,15,8,CH,A)
DUPKEYS MAX=(23,4,BI)
|
Since all the SORT fields in your control cards are continous fields we can club them into a single field and sort it as binary. Since you want to get the max value , you can sort on the filed 23,4,bi Ascending and the last value will be max value record. Trailer3 will pull the last record for each key (1,22)
Code: |
//STEP0100 EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SORTIN DD *
----+----1----+----2----+----3----+----4
A 1000
A 9000
A 7000
A 8000
B 6000
B 3000
B 1000
//SORTOUT DD SYSOUT=*
//SYSIN DD *
OPTION EQUALS
SORT FIELDS=(01,22,BI,A,
23,04,BI,A)
OUTFIL REMOVECC,NODETAIL,
SECTIONS=(1,22,TRAILER3=(1,80))
/* |
Alternatively you can sort on the 23,4,bi descending so that the Max value is the first record for every group. using RESTART parm we number the duplicates and pick only the first record which is the max value record.
Code: |
//STEP0100 EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SORTIN DD *
A 1000
A 9000
A 7000
A 8000
B 6000
B 3000
B 1000
//SORTOUT DD SYSOUT=*
//SYSIN DD *
OPTION EQUALS
SORT FIELDS=(01,22,BI,A,
23,04,BI,D)
OUTREC OVERLAY=(81:SEQNUM,8,ZD,RESTART=(1,22))
OUTFIL BUILD=(1,80),INCLUDE=(81,8,ZD,EQ,1)
/* |
or
If you think the idea of numbering the duplicates is cumbersome, you can use the DFSORT/ICETOOL's SELECT operator which lets you pick the record you want. In this case we want the first record when the max value is sorted descending.
Code: |
//STEP0300 EXEC PGM=ICETOOL
//TOOLMSG DD SYSOUT=*
//DFSMSG DD SYSOUT=*
//IN DD *
A 1000
A 9000
A 7000
A 8000
B 6000
B 3000
B 1000
//OUT DD SYSOUT=*
//TOOLIN DD *
SELECT FROM(IN) TO(OUT) ON(1,22,BI) FIRST USING(CTL1)
//CTL1CNTL DD *
SORT FIELDS=(01,22,BI,A,
23,04,BI,D)
/* |
|
|