SUM FIELDS
A DFSORT control statement that combines records with the same sort key into one, adding up chosen numeric fields.
Also written SUM FIELDS=NONE, DFSORT SUM, remove duplicate records
SUM FIELDS is a DFSORT statement that works on records with equal keys. After sorting, any records that have the same value in the SORT FIELDS key are combined into one record.
With fields named, it adds them up. SUM FIELDS=(20,8,PD) adds the eight-byte packed decimal field starting at position 20 across all records with the same key, so a file of transactions becomes one record per account with the total amount. The other fields come from one of the combined records.
SUM FIELDS=NONE adds nothing. It simply keeps one record for each key and drops the rest, which is the standard way to remove duplicates. Which record is kept can depend on options such as EQUALS, which keeps records with equal keys in their original order.
If a total is too large for its field, DFSORT stops adding to that record and reports an overflow. For more control over duplicates, such as writing the dropped records to a separate file, ICETOOL's SELECT operator is the usual choice.
Where can I learn this hands-on?
Right here, at ZedBank. You take a junior job at a simulated bank and learn each part of the work by doing it, with Zed beside you. There's nothing to install.
Start at ZedBankRelated
- DFSORTThe standard sort utility, used far beyond sorting to select, merge, reformat and summarise records at speed.
- SORT FIELDSA DFSORT control statement that says what to put in order: where the field is, how long it is, what kind of data, and which way.
- ICETOOLA DFSORT utility that runs several sort, copy, count and report operations in one job step.
- OMIT CONDA DFSORT control statement that leaves out the records that match a test. INCLUDE COND does the opposite and keeps only the matches.
- OUTREC BUILDA DFSORT control statement that builds each output record as a list of pieces: columns from the input and fixed text.