SUM is a keyword used in SAP ABAP programming.This tutorial covers its introduction & syntax details.
SUM
Basic form
SUM.
Effect
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/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 ).
Example
Display the table T with sub-totals:
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.
Notes
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 internal table.
When
using LOOP to process a sorted extract (see SORT ), the control total
of f at the end of the group appears in the field SUM(f) - - if f is
type I , F or P .
Note
Runtime errors
SUM_OVERFLOW : Value too large when calculatng totals in internal table, field too small.
SUM_NO_INTERNAL_TABLE : The SUM statement was used outside a LOOP on an internal table.
SUM_ON_FOREIGN_INTERNAL_TABLE : The SUM statement was used in a LOOP belonging to another ABAP/4 program.
Related 10 ABAP Syntax Tutorials
Most readed SAP Tutorials
- WRITE - Output to a list ( SAP ABAP Keyword)
WRITE ( Output to a list ) is a keyword used in SAP ABAP programming.This tutorial covers its introduction & syntax details. - List of SAP HR TABLES and Infotypes tables
Detailed full list of tables and infotypes used in SAP HR module. - List of SAP MM Transaction codes
This documentation covers the details of SAP MM Transaction codes - SELECT-OPTIONS ( SAP ABAP Keyword)
SELECT-OPTIONS is a keyword used in SAP ABAP programming.This tutorial covers its introduction & syntax details. - FI Accounts Receivable and Accounts Payable | SAP FI PDF manual
The following topics are an introduction to the Accounts Receivable and Accounts Payable application components. - SELECT clause ( SAP ABAP Keyword)
SELECT clause is a keyword used in SAP ABAP programming.This tutorial covers its introduction & syntax details. - SAP MM Process Flow
The typical procurement cycle for a service or material consists of the following phases:
Latest Added SAP documents
- 9KE9 Transaction code
Details about SAP transaction code 9KE9 - 9KE8 Transaction code
Details about SAP transaction code 9KE8 - 9KE7 Transaction code
Details about SAP transaction code 9KE7 - 9KE6 Transaction code
Details about SAP transaction code 9KE6 - 9KE5 Transaction code
Details about SAP transaction code 9KE5 - 9KE4 Transaction code
Details about SAP transaction code 9KE4 - 9KE3 Transaction code
Details about SAP transaction code 9KE3 - 9KE2 Transaction code
Details about SAP transaction code 9KE2 - 9KE1 Transaction code
Details about SAP transaction code 9KE1 - 9KE0 Transaction code
Details about SAP transaction code 9KE0