SUM: Suppressing duplicate records


  • Apart from summing values, SUM used to delete records which are having duplicate values in the control fields specified.

Syntax -


SUM FIELDS=NONE
NONE Specifies to SORT that no duplicates in output

Example -


Scenario - From the below data, Remove the duplicate records at department level.

Input File - MTH.SORT.INPUT

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

Input Record Layout -

01 INPUT-REC.
	05 STD-ID			PIC X(05).
	05 FILLER			PIC X(05).
	05 STD-NAME			PIC X(15).
	05 FILLER			PIC X(05).
	05 STD-DEPT			PIC X(10).
	05 FILLER			PIC X(05).
	05 STD-MARKS		PIC 9(03).
	05 FILLER			PIC X(32).

JCL -

----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
***************************** Top of Data ******************************
//Job-card
//*                                                                     
//**********************************************************************
//*                                                                     
//* SORT SUM STATEMENT                                                  
//*                                                                     
//**********************************************************************
//STEP01   EXEC PGM=SORT                                                
//SORTIN   DD DSN=MTH.SORT.INPUT01,DISP=SHR                    
//SORTOUT  DD SYSOUT=*                                                  
//SYSOUT   DD SYSOUT=*                                                  
//SYSIN    DD *                                                         
     SORT FIELDS=(30,10,CH,A)                                           
     SUM  FIELDS=NONE
/*                                                                      
**************************** Bottom of Data ****************************

Output -

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

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. The SORT condition for the above requirement with all the data gathered is -
    SORT FIELDS=(30,10,CH,A)
  3. The above sort condition specifies all the duplicates should be dropped with the department as key.
  4. The output would have the first records of duplicates and non-duplicate records.