SUM Handling Overflow - VLSHRT Example


Scenario - Sum the marks at department level.

Input File - MATEPK.SORT.INPUT02

----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8
00001     student1            dept1          560
00002     student2            dept3          510
00003     student3            dept2          520
00004     student4            dept1          540
00005     student5            dept2          500

JCL -

----+----1----+----2----+----3----+----4----+----5----+
//MATEPKD  JOB (123),'MTH',NOTIFY=&SYSUID
//*
//STEP01   EXEC PGM=SORT
//SORTIN   DD DSN=MATEPK.SORT.INPUT02,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 *
     OPTION VLSHRT
     SORT FIELDS=(30,10,CH,A)
     SUM  FIELDS=(45,03,ZD)
/*

Output -

----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8
00001     student1            dept1          560
00002     student2            dept3          510
00003     student3            dept2          520
00004     student4            dept1          540
00005     student5            dept2          500

Explaining Example -

  1. The summing of the marks at department level was not happened because there is an overflow if 560 and 540 added.
  2. The total exceeds 999 which is the maximum value in 3 bytes. So the records are not summed and simply sorted.