SUM Suppressing Duplicate Records Example


Scenario - Remove the duplicate records at department level.

Input File - MATEPK.SORT.INPUT

----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8
00001     student1            dept1          095
00003     student3            dept2          070
00004     student4            dept1          090
00005     student5            dept2          083
00002     student2            dept3          088

JCL -

----+----1----+----2----+----3----+----4----+----5----+
//MATEPKD  JOB (123),'MTH',NOTIFY=&SYSUID
//*
//STEP01   EXEC PGM=SORT
//SORTIN   DD DSN=MATEPK.SORT.INPUT01,DISP=SHR
//SORTOUT   DD DSN=MATEPK.MERGE.OUTPUT,
//            DISP=(NEW,CATLG,DELETE),UNIT=SYSDA,
//            SPACE=(CYL,(1,4),RLSE),
//            DCB=(RECFM=FB,LRECL=80,BLKSIZE=0)
//SYSOUT   DD SYSOUT=*
//SYSIN    DD *
     SORT FIELDS=(30,10,CH,A)
     SUM  FIELDS=NONE
/* 

Output -

----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8
00001     student1           dept1          095
00003     student3           dept2          070
00002     student2           dept3          088

Explaining Example -

  1. As per requirement, department level duplicates needs to be eliminated. So the STD-DEPT position, length, format required for SORT FIELDS. STD-MARKS start from 30th position of length 10 and type is alphanumeric as per declaration. So use CH.
  2. SORT FIELDS=(30,10,CH,A)
    - specifies all the duplicates should be dropped with the department as key.
  3. The output would have the first records of duplicates and non-duplicate records.