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, it displays the last value retrieved from the data source.

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


Top of page

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: If you are using the external sorting product DFSORT, you can set the SUMPREFIX parameter to FST or LST to control the sort order. For details, see Sorting Tabular Reports.


WebFOCUS