Adding Values

SUM, WRITE, and ADD sum the values of a numeric field. The three commands are synonyms; they can be used interchangeably, and every reference to SUM in this documentation also refers to WRITE and ADD.

When you use SUM, multiple records are read from the data source, but only one summary line is produced. If you use SUM with a non-numeric field—such as an alphanumeric, text, or date field—SUM does not add the values. Instead, by default, it displays the last value retrieved from the data source. You can change this to the first value, minimum value, or maximum value using the SUMPREFIX parameter.

For SUM, WRITE, and ADD syntax, see Use Display Commands in a Request.

Example: Adding Values

This request adds all the values of the field CURR_SAL:

TABLE FILE EMPLOYEE
SUM CURR_SAL
END

The following shows the output of the request.

   CURR_SAL
   --------
$222,284.00

Example: Adding Non-Numeric Values

This request attempts to add non-numeric fields. Any request for aggregation on non-numeric data returns the last record retrieved from the data source.

TABLE FILE EMPLOYEE
SUM LAST_NAME AND FIRST_NAME
END

The following shows the output of the request.

LAST_NAME
FIRST_NAME
---------
----------
CROSS
BARBARA

 

Note that any request for aggregation on all date format fields also returns the last record retrieved from the data source.

Tip: You can set the SUMPREFIX parameter to FST, MIN, MAX, or LST to control the sort order. For details, see Sorting Tabular Reports.