SUM: Handling overflow - VLSHRT
SUM: Handling overflow - VLSHRT
Summary
- The overflow occurs when summed value becomes larger than the space/size available for it.
- The summary fields from the two records involved are not added together if overflow occurs.
- The records are kept unchanged; neither record is deleted if overflow occurs.
Syntax -
OPTION VLSHRT
SORT FIELDS=sort_options
SUM FIELDS=sort_options
- VLSHRT communicates DFSORT to ignore the records with short summary fields un-summed.
- One of the two records involved in a summary operation has a short summary field, the records are kept unchanged; neither record is deleted.
- By Default, NOVLSHRT is in effect.
Note! If NOVLSHRT is in effect or not specified, DFSORT terminates if it finds a shortsummary field in any VB record.
Example -
Scenario - From the below data, sum the marks at department level.
Input File - MTH.SORT.INPUT02
----+----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 WITH OVERFLOW STATEMENT
//*
//**********************************************************************
//STEP01 EXEC PGM=SORT
//SORTIN DD DSN=MTH.SORT.INPUT02,DISP=SHR
//SORTOUT DD SYSOUT=*
//SYSOUT DD SYSOUT=*
//SYSIN DD *
OPTION VLSHRT
SORT FIELDS=(30,10,CH,A)
SUM FIELDS=(45,03,ZD)
/*
**************************** Bottom of Data ****************************
Output -
----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8
********************************* TOP OF DATA **********************************
00001 student1 dept1 560
00002 student2 dept3 510
00003 student3 dept2 520
00004 student4 dept1 540
00005 student5 dept2 500
******************************** BOTTOM OF DATA ********************************
Explaining Example -
- The summing of the marks at department level was not happened because there is an overflow if 560 and 540 added.
- The total exceeds 999 which is the maximum value in 3 bytes. So the records are not summed and simply sorted.