SUM Handling overflow - VLSHRT


The SUM statement is used to summing numeric fields or eliminate duplicate records based on specified fields. When handling numeric summing, an overflow can occur if the total exceeds the length of the field. The VLSHRT option allows DFSORT to handle this overflow by truncating the result to fit the field size instead of producing an error.

Syntax -

//SYSIN    DD *
  OPTION VLSHRT
  SORT FIELDS=sort_options
  SUM FIELDS=sort_options
/*

Points to Note -

  • 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.

Examples -


Scenario1 - Summing zoned decimal fields with VLSHRT.

//SYSIN   DD  *
  OPTION VLSHRT
  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 exceeds the 5-byte zoned decimal field length, the result is truncated to fit within the field size, avoiding overflow errors.

Scenario2 - Summing packed decimal fields with VLSHRT.

//SYSIN   DD  *
  OPTION VLSHRT
  SORT FIELDS=(1,8,CH,A)
  SUM FIELDS=(9,4,PD)
/*

Summing the 4-byte packed decimal field starting at position 9. If the sum exceeds the 4-byte packed decimal field size, the result is truncated to fit the 4-byte field, preventing an overflow error.