SUM Handling overflow - NOVLSHRT
The SUM statement is used to sum or eliminate duplicate records based on specified fields. When handling numeric summing, overflow can occur if the total exceeds the length of the field. The NOVLSHRT option is used to prevent overflow when it occurs, and instead, it will result in an error, ensuring the user is informed of the overflow.
Syntax -
//SYSIN DD *
OPTION NOVLSHRT
SORT FIELDS=sort_options
SUM FIELDS=sort_options
/*
Points to Note -
- NOVLSHRT communicates DFSORT to fail the job if overflow happened.
- By Default, NOVLSHRT is in effect.
- If NOVLSHRT is not in effect or not coded, DFSORT ignores the records where it got overflow.
Examples -
Scenario1 - Summing zoned decimal fields with NOVLSHRT.
//SYSIN DD *
OPTION NOVLSHRT
SORT FIELDS=(1,10,CH,A)
SUM FIELDS=(11,5,ZD)
/*
Summing the 5-byte zoned decimal field starting at position 11. If the sum of values exceeds the field length (5 bytes in this case), DFSORT will terminate with an overflow error instead of truncating the result.
Scenario2 - Summing packed decimal fields with NOVLSHRT.
//SYSIN DD *
OPTION NOVLSHRT
SORT FIELDS=(1,8,CH,A)
SUM FIELDS=(9,4,PD)
/*
Summing the 4-byte packed decimal field starting at position 9. Ensures that if the sum exceeds the 4-byte packed decimal field length, an overflow error is reported instead of truncating the result.