When processing an internal table in a block starting with
and concluded by ENDLOOP,
SUM calculates the control totals of all fields of type I, F and P
(see also ABAP/4 number types) and places them in the LOOP
output area (header line of the internal table or an explicitly
specified work area).
You can use the SUM statement both at the end and the beginning of a control group (see also AT FIRST/LAST).
DATA: BEGIN OF T OCCURS 100, CODE(4), SALES TYPE P, DISCOUNT TYPE P, END OF T. ... LOOP AT T. AT FIRST. SUM. WRITE: /4 'Grand Total:', 20 T-SALES, 40 T-DISCOUNT. ULINE. SKIP. ENDAT. WRITE: / T-CODE, 20 T-SALES, 40 T-DISCOUNT. AT END OF CODE. SUM. WRITE: / T-CODE, 10 'Total:', 20 T-SALES, 40 T-DISCOUNT. SKIP. ENDAT. ENDLOOP.
When you use SUM in a LOOP with an explicitly specified output
area, this output area must be compatible with the line type of the