Trailer COUNT and TOTAL Syntax

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.

Report Generation
Progress0 of 0 lessons

COUNT= Syntax

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:

text
1
COUNT=(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= (TOT=) Syntax

TOTAL= (or TOT=) sums a numeric field and inserts the result in the trailer. Typical form:

text
1
TOTAL=(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 Meanings (TOTAL=)

Numeric formats for TOTAL=
FormatMeaning
PDPacked decimal. Common on mainframe; 2 digits per byte except last (sign). Length in bytes is (digits/2)+1 or similar; match your record layout.
ZDZoned decimal. One digit per byte; sign in low nibble of last byte. len = number of digits.
BIBinary (fullword or doubleword). len usually 4 or 8.

Positioning in the Trailer Line

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.

text
1
2
TRAILER1=(1:'TOTAL RECORDS: ',COUNT=(M11,LENGTH=7), 25:' TOTAL AMOUNT: ',TOTAL=(40,6,PD,LENGTH=12))

Multiple COUNT= and TOTAL=

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.

Explain It Like I'm Five

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.

Exercises

  1. Write TRAILER1= that prints “Records: ” then the count (LENGTH=8) and “ Total: ” then the sum of a 5-byte ZD field at position 30, output length 10.
  2. Why must the format in TOTAL= match the data type (PD vs ZD)?
  3. What is the scope of COUNT= in TRAILER3 vs TRAILER1?

Quiz

Test Your Knowledge

1. In TOTAL=(start,len,format,LENGTH=n), what do start and len refer to?

  • Output position and length
  • Start position and length of the numeric field in the input (or INREC) record to sum; format is the data format (PD, ZD, BI)
  • Page and line
  • Header position only

2. What does COUNT=(M11,LENGTH=7) mean?

  • Count 7 records only
  • Insert the record count, edited with mask M11 (product-dependent), in a field of width 7 in the trailer
  • Count only position 11
  • Maximum count 11

3. Which format would you use for TOTAL= if the field is packed decimal?

  • CH
  • PD
  • ZD
  • BI only

4. Can you have multiple TOTAL= items in one TRAILER1?

  • No, only one
  • Yes—you can list multiple TOTAL=(pos,len,format,LENGTH=n) and literals to sum several fields in the same trailer line
  • Only in TRAILER3
  • Only with COUNT=

5. Do COUNT= and TOTAL= in TRAILER3 use the same syntax as in TRAILER1?

  • No, different syntax
  • Yes—same syntax; the difference is scope: TRAILER3 is per section (so count and total for that section only), TRAILER1 is for the whole report
  • Only TRAILER1 has TOTAL=
  • TRAILER3 has no COUNT=