Navigation: Language Reference > 9 - Window and Report Attributes > Window and Report Attributes >====== SUM (set total) ====== | |
SUM( [ variable ] )
SUM | Calculates the the sum of the values contained in the STRING control's USE variable. |
variable | The label of a numeric variable to receive the intermediate values calculated for the SUM. This allows you to create totals on other totals. The value in the variable is internally updated by the print engine, so it is only useful for use within the REPORT structure. |
The SUM attribute (PROP:SUM) specifies printing the sum of the values contained in the STRING control's USE variable. Unless the TALLY attribute is present, the result is calculated as follows:
·A SUM field in a DETAIL structure increments each time the DETAIL structure containing the control PRINTs. This provides a “running” total.
·A SUM field in a group FOOTER structure increments each time any DETAIL structure in the BREAK structure containing the control PRINTs. This provides the sum of the value contained in the variable in the group.
·A SUM field in a page FOOTER structure increments each time any DETAIL structure in any BREAK structure PRINTs. This is the sum of the values contained in the variable in the page.
·A SUM field in a HEADER is meaningless, since no DETAIL structures will have been printed at the time the HEADER is printed.
The SUM value is reset only if the RESET or PAGE attribute is also specified.
Example:
CustRpt REPORT,AT(1000,1000,6500,9000),THOUS
Break1 BREAK(LocalVar),USE(?BreakOne)
Break2 BREAK(Pre:Key1),USE(?BreakTwo)
Detail DETAIL,AT(0,0,6500,1000),USE(?DetailOne)
STRING(@N$11.2),AT(6000,1500,500,500),USE(Pre:F1)
END
FOOTER,AT(0,0,6500,1000),USE(?BreakOneGroupFoot)
STRING('Group Total:'),AT(5500,500)
STRING(@N$11.2),AT(6000,500),USE(Pre:F1),SUM(LocalVar),RESET(Break2)
END
END
FOOTER,AT(0,0,6500,1000),USE(?BreakOneGroupFoot)
STRING('Grand Total:'),AT(5500,500)
STRING(@N$11.2),AT(6000,500),USE(LocalVar),SUM,TALLY(?BreakTwo)
END
END
END