DUPKEYS Control Statement
The DUPKEYS control statement is used to enable special processing for records with equal sort/merge control fields (keys). You can perform the following functions:
• Sum specified numeric fields, place the sum in one record and delete the other records with the same key (SUM)
• Compute the average of specified numeric fields, place the average in one record and delete the other records with the same key (AVG)
• Determine the minimum or maximum value of specified numeric fields, place this value in one record and delete the other records with the same key (MIN,MAX)
• Delete all but one of the records with equal keys (FIELDS=NONE)
• Retain only records with keys that occur more than once (ALLDUPS)
• Retain only the first record of those with keys that occur more than once (FIRSTDUP)
• Retain only the last record of those with keys that occur more than once (LASTDUP)
• Retain only the records with keys that occur only once (NODUPS)
The records deleted by DUPKEYS can optionally be written to a separate file.
The DUPKEYS control statement cannot be used with a SUM control statement, nor when FIELDS=COPY is specified on the SORT or MERGE control statement.
If you need to add other DUPKEYS functionality to an application with a SUM control statement, you must move the SUM specification to the DUPKEYS statement and remove the SUM statement. If XSUM was used, then XDUP should be specified and the JCL changed from using a SORTXSUM DD to a SORTXDUP DD.
Javas and Pythons come and go, but JCL and SORT stay forever.