The PRINT TOTAL statement prints numeric field totals as well as control fields for subtotals. You can specify up to 13 fields to total and 12 control fields. You cannot total alphanumeric fields. The values in the totaled fields are accumulations of values from all records that are passed to the PRINT and PRINT TOTAL statements.
The control field values "controlfield1 WITHIN controlfield2 ... WITHIN controlfieldn" describe a sort key in ascending sort order. The PRINT TOTAL statement produces unpredictable results unless the data for the step is in the order of the sort key. Presort the data in ascending order by using a SORT statement before the PRINT TOTAL statement.
If you use a PRINT statement and a PRINT TOTAL statement, the total is printed below the detail values for any field used in both statements.
The first 24 positions of each line of subtotals are reserved for any specified literal or for blanks if you supply no literals. Place fields at least 24 print positions into the print line to keep the totals from being overprinted by the literal.
The syntax is as follows:
PRINT TOTAL "Parms".
Parms:
totalfield ... [BY controlfield [literal]] [SPACED n] [SKIP] [WITHIN controlfield [literal]] ...
- totalfield
Indicates the names of the fields to total. Alphanumeric fields (TYPE A/N) cannot be totaled. - controlfield
Indicates the names of control fields determining the different summary levels of totals to be produced. - literal
Indicates constants of up to 24 characters enclosed in quotes, which are printed as labels for the associated total lines. - SPACED n
Indicates 1 (single), 2 (double), or 3 (triple) spacing. The SPACED parameter affects the spacing that follows subtitle lines in the output. The default is 1. - SKIP
Causes a page eject after the subtotal line.
Example
This statement prints total session connect time and total CPU time, with subtotals, by user ID and date:
PRINT TOTAL TOTCPU CONNTIME BY USERID 'SUBTOTAL FOR USER'
SPACED 2 WITHIN ENDDATE 'SUBTOTAL FOR DATE' SPACED 2.
In this example, there should be an associated PRINT statement with enough fields or literals before TOTCPU and CONNTIME to place these fields at least 24 spaces into the print line. The SPACED 2 parameter in this example specifies that one blank line is placed after each subtotal.