SUM
Syntax
![]()
Command
Mandatory parameter Optional parameter Mandatory keyword Optional keyword |
SUM (<Source>, <Result>)
Description
When used inside a loop, a 'readfile loop' or 'query loop' and in conjunction with the LEVEL_BREAK command the total sum of the source values between two level breaks is calculated and the result is copied into the result variable.
Diagram
Returned value type
None
Parameters
Parameter | Description |
Source |
The name of the variable to calculate the total sum of. |
Result |
The name of the object to place the resulting total sum in. |
Remark
Sum will only work in conjunction with the LEVEL_BREAK command inside a 'readfile' or 'query' loop.
Example
readfile (lbfile, rec_lbf)
lay_emp.dept := rec_lbf.dept
lay_emp.empnr := rec_lbf.empnr
lay_emp.salary := rec_lbf.salary
lay_hdr.hdept := rec_lbf.dept
level_break (rec_lbf.dept, lay_ftr, lay_hdr, 3)
average (rec_lbf.salary, lay_ftr.avgsal)
mean_squares (rec_lbf.salary, lay_ftr.msqsal)
std_deviation (rec_lbf.salary, lay_ftr.stdsal)
sum (rec_lbf.salary, lay_ftr.varsal)
print (lay_emp)
endread
lay_emp.dept := rec_lbf.dept
lay_emp.empnr := rec_lbf.empnr
lay_emp.salary := rec_lbf.salary
lay_hdr.hdept := rec_lbf.dept
level_break (rec_lbf.dept, lay_ftr, lay_hdr, 3)
average (rec_lbf.salary, lay_ftr.avgsal)
mean_squares (rec_lbf.salary, lay_ftr.msqsal)
std_deviation (rec_lbf.salary, lay_ftr.stdsal)
sum (rec_lbf.salary, lay_ftr.varsal)
print (lay_emp)
endread