SUM control statement
.-,-----. V | >>-SUM--FIELDS=--+-(----p,m,f-+--)--------------------+-------->< | .-,-----------. | | V | | +-(----p,m--+----+-+--)--,--FORMAT=f-+ | '-,f-' | '-NONE-------------------------------'
The SUM control statement specifies that, whenever two records are found with equal sort or merge control fields, the contents of their summary fields are to be added, the sum is to be placed in one of the records, and the other record is to be deleted. If the EQUALS option is in effect the first record of summed records is kept. If the NOEQUALS option is in effect, the record to be kept is unpredictable. For further details, see SUM statement notes.
If the ZDPRINT option is in effect, positive summed ZD values are printable. If the NZDPRINT option is in effect, positive summed ZD values are not printable. For further details, see SUM statement notes.
The way in which DFSORT processes short SUM summary fields depends on whether the VLSHRT or NOVLSHRT option is in effect. A short field is one where the variable-length record is too short to contain the entire field; that is, the field extends beyond the record. For details about sorting, merging and summing short records, see the discussion of the VLSHRT and NOVLSHRT options in OPTION control statement.
- FIELDS
.-,-----. V | >>-FIELDS=--(----p,m,f-+--)------------------------------------><
Designates numeric fields in the input record as summary fields.
- p
- specifies the first byte of the field relative to the beginning of the input record. 1 The first data byte of a fixed-length record has relative position 1. The first data byte of a variable-length record has relative position 5, as the first four bytes are occupied by the RDW. All fields must start on a byte boundary and no field can extend beyond byte 32752
- m
- specifies the length in bytes of the summary fields to be added. See Table 1for permissible length values.
- f
- specifies the format of the data in the summary field:
Table 1. Summary Field Formats and Lengths Summary Field Formats and LengthsFormat CodeLength Description BI 2, 4, or 8 bytes Unsigned binary FI 2, 4, or 8 bytes Signed fixed-point FL 4, 8, or 16 bytes Signed hexadecimal floating-point PD 1 to 16 bytes Signed packed decimal ZD 1 to 31 bytes Signed zoned decimal The value for f can optionally be specified by the FORMAT=f parameter as explained later in this section.
Note: See Data format descriptions for detailed format descriptions. - NONE
- eliminates records with duplicate keys. Only one record with each key is kept and no summing is performed.
Note: The FIRST operand of ICETOOL's SELECT operator can be used to perform the same function as SUM FIELDS=NONE with OPTION EQUALS. Additionally, SELECT's FIRSTDUP, ALLDUPS, NODUPS, HIGHER(x), LOWER(y), EQUAL(v), LASTDUP, and LAST operands can be used to select records based on other criteria related to duplicate and non-duplicate keys. SELECT's DISCARD(savedd) operand can be used to save the records discarded by FIRST, FIRSTDUP, ALLDUPS, NODUPS, HIGHER(x), LOWER(y), EQUAL(v), LASTDUP, or LAST. See SELECT operator for complete details on the SELECT operator.Default: None; must be specified.
Applicable Functions: See Specification/override of DFSORT options.
- FORMAT
>>-FORMAT=f----------------------------------------------------><
FORMAT=f can be used to specify a particular format for one or more summary fields. f from FORMAT=f is used for p,m fields. f from FORMAT=f is ignored for p,m,f fields. For example, the following are all equivalent:
The permissible field formats are shown under the description of 'f' for fields.SUM FIELDS=(5,5,ZD,12,6,PD,21,3,PD,35,7,ZD) SUM FORMAT=ZD,FIELDS=(5,5,12,6,PD,21,3,PD,35,7) SUM FIELDS=(5,5,ZD,12,6,21,3,35,7,ZD),FORMAT=PD
Default: None. FORMAT=f must be specified if any field is specified as p,m rather than p,m,f. See Specification/override of DFSORT options for full override details.
Applicable Functions: See Specification/override of DFSORT options.