In DFSORT OUTFIL, TRAILER1 and TRAILER3 can include COUNT= (record count) and TOTAL= (or TOT=) (sum of a numeric field). Getting the syntax right ensures the right numbers appear in the right place. This page details the syntax for COUNT= and TOTAL= in trailers: the meaning of position and length, the format (PD, ZD, BI), the LENGTH operand for the output width, and how to combine them with literals and positioning. Product-specific edit masks (e.g. M11) for COUNT= are mentioned; your manual has the exact list.
COUNT= inserts the number of records in the current scope. In TRAILER1 the scope is all data records in the report; in TRAILER3 it is the current section only. Common form:
1COUNT=(format,LENGTH=n)
format is an edit mask (e.g. M11, M10) that controls whether the number has commas, leading zeros, etc. LENGTH=n is the number of character positions the count will occupy in the trailer line. If the count is larger than n digits, the result may be truncated or the format may allow overflow; check your product. Example: COUNT=(M11,LENGTH=7) gives a 7-character field with the record count, edited per M11.
TOTAL= (or TOT=) sums a numeric field and inserts the result in the trailer. Typical form:
1TOTAL=(start,len,format,LENGTH=outlen)
start — Starting position (1-based) of the field in the input record (as seen by OUTFIL; after INREC if used). len — Length in bytes of the field. format — Data format: PD (packed decimal), ZD (zoned decimal), BI (binary). Must match the actual data. LENGTH=outlen — Width in characters of the formatted total in the trailer. Example: TOTAL=(40,6,PD,LENGTH=12) sums the 6-byte packed decimal at positions 40–45 and writes the result in 12 characters.
| Format | Meaning |
|---|---|
| PD | Packed decimal. Common on mainframe; 2 digits per byte except last (sign). Length in bytes is (digits/2)+1 or similar; match your record layout. |
| ZD | Zoned decimal. One digit per byte; sign in low nibble of last byte. len = number of digits. |
| BI | Binary (fullword or doubleword). len usually 4 or 8. |
Use position:value to place items. For example 1:\'Total: \' puts the literal at column 1. Then COUNT=(M11,LENGTH=7) follows immediately after. To start the total at column 25, use 25:\'Sum=\',TOTAL=(40,6,PD,LENGTH=12). The slash (/) starts a new line.
12TRAILER1=(1:'TOTAL RECORDS: ',COUNT=(M11,LENGTH=7), 25:' TOTAL AMOUNT: ',TOTAL=(40,6,PD,LENGTH=12))
You can have one COUNT= and several TOTAL= in the same trailer, each for a different field. Combine literals and positioning so the line is readable. Example: section header, count, total for field A, total for field B.
COUNT= is like asking “how many?” and putting that number in a box that’s 7 spaces wide, maybe with commas. TOTAL= is like adding up a column of numbers (you tell it where the column is and how big each number is) and writing the sum in another box. You get to say where on the line each box goes (position:...) so the line looks nice.
1. In TOTAL=(start,len,format,LENGTH=n), what do start and len refer to?
2. What does COUNT=(M11,LENGTH=7) mean?
3. Which format would you use for TOTAL= if the field is packed decimal?
4. Can you have multiple TOTAL= items in one TRAILER1?
5. Do COUNT= and TOTAL= in TRAILER3 use the same syntax as in TRAILER1?