Considerations for aggregation functions and edit codes
QMF calculates the result of an aggregation function based on the actual values stored in the database table, not on the values resulting from the edit code for a column.
To obtain the aggregation result using the values resulting from the edit code for a column, you must use an alternative method such as defining a new column and then using a REXX function.
For example:
- Create and save the following query, naming it Q1:
SELECT 10.5 from Q.ORG
- Issue the command
RUN Q1 (ROW 2
. The report appears as follows:COL1 ------ 10.5 10.5
- Issue the command
SH F. COL
. - Position the cursor under
COL1
, and press the Insert function key. - Type
COLNEW
under COLUMN HEADING,SUM
under USAGE for bothCOL1
andCOLNEW
, and change the edit code forCOLNEW
toL
as shown in the following figure:Figure 1. Obtaining an aggregation result using values from the edit code for a column FORM.COLUMNS MODIFIED Total Width of Report Columns: 20 NUM COLUMN HEADING USAGE INDENT WIDTH EDIT SEQ --- --------------------------- ------- ------ ----- ----- --- 1 COL1 SUM 2 6 L1 1 2 COLNEW SUM 2 10 L 1 *** END ***
- Position the cursor under
COLNEW
, and press the Specify function key. - Choose Definition, and then press Enter.
- Type the following REXX expression,
and then press Enter:
format(&1,5,0)
- Press the Cancel function key to close the Specify window.
- Press the Report function key to display the following report:
COL1 COLNEW ------ ---------- 10.5 11 10.5 11 ====== ========== 21.0 22
Note that COLNEW has rounded values for each row and that the sum is the sum of the rounded values.