The SUMMARIZE statement writes an output record of summarized values whenever one or more specified control fields change. You can specify 13 fields to summarize and 12 control fields. SUMMARIZE differs from PRINT TOTAL in that nothing is printed by SUMMARIZE.

A SUMMARIZE statement signifies the end of a processing step.

If you intend to use the summarized data in another processing step, use a DEFINE statement to define a work field to hold the value produced by the SUMMARIZE statement. The DISPLAY 'dcon' parameter in the DEFINE statement controls the size of the work field. For more information, see the section DEFINE Statement.

The syntax is as follows:

SUMMARIZE "Parms".

Parms:

totalfield ... 
BY controlfield ...
[WITHIN controlfield] ...
INCLUDING fieldname ...
[TO ddname]
  • totalfield
    Specifies the name of a summarized field. The summarized value is included in an output record written to disk. Alphanumeric fields (TYPE A/N) cannot be summarized. Up to 13 field names may be summarized.
  • controlfield
    Specifies the name of a control field. One control field name is required after the BY keyword. Up to 12 additional control field names may each follow a WITHIN keyword. A new record is written whenever the value in one of the control fields changes. The control fields are written to disk along with the summarized fields.
  • fieldname
    Specifies the name of an additional field. Up to 12 additional fields are written to the output file along with the group of total fields. These fields are not summarized. They should correspond in some way to the control fields, or their inclusion in the record is not meaningful.
  • ddname
    Indicates a name (defined by a FILEDEF command) where the output records are written. The default output destination is FILE SORTIN A. If you did not issue a FILEDEF command for ddname, the output is written to a file named FILE ddname A.

Example

This statement creates summary records, one per user ID, containing the user ID and the totaled value of the PUNLINES and PRTLINES fields:

SUMMARIZE PUNLINES PRTLINES BY USERID.