SUM.
When processing an internal table in a block starting with
LOOP and concluded by ENDLOOP,
SUM calculates the control totals of all fields of type
I, F and
P (see also ABAP 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).
Display the table T with sub-totals:
TYPES: BEGIN OF T_TYPE,
CODE(4),
SALES TYPE P,
DISCOUNT TYPE
P,
END OF T_TYPE.
DATA: T TYPE STANDARD TABLE OF T_TYPE
WITH NON-UNIQUE
DEFAULT
KEY INITIAL SIZE 100,
WA_T TYPE T_TYPE.
...
LOOP AT
T INTO WA_T.
AT FIRST.
SUM.
WRITE:
/4 'Grand Total:',
20 WA_T-SALES,
40 WA_T-DISCOUNT.
ULINE. SKIP.
ENDAT.
WRITE:
/ WA_T-CODE,
20 WA_T-SALES, 40 WA_T-DISCOUNT.
AT END OF CODE.
SUM.
WRITE:
/ WA_T-CODE, 10 'Total:',
20 WA_T-SALES, 40 WA_T-DISCOUNT.
SKIP.
ENDAT.
ENDLOOP.
Catchable Exceptions
CX_SY_ARITHMETIC_OVERFLOW
Non-Catchable Exceptions
Processing Table Lines in Loops