Get Example source ABAP code based on a different SAP table
ID SUM • SUM ABAP Statement
SUM> Short Reference >
ABAP_SYNTAX SUM.>
What does it do? The statement SUM> can only be specified within a loop LOOP>> and is only respected within a AT>-ENDAT>> control structure. Prerequisites for using the statement SUM> are that the addition INTO> is used in the LOOP> statement, and that the specified work area wa> is compatible > with the line type of the internal table. Furthermore, SUM> cannot be used when the line type of the internal table itab> contains components that are tables themselves.
In a group level AT NEW compi> and AT END OF compi>, SUM > calculates the sums of the numeric > components to the right of the current group key for all lines of the current group level and assigns these to the corresponding components of the work area wa>. In an elementary line type, there are no components to the right of the current group key and the work area wa> remains unchanged.
In the group levels FIRST>, LAST>, and outside an AT>- ENDAT> control structure, for a structured line type the sum of all numeric components of all lines of the internal table is calculated and assigned to the corresponding components of the work area wa>. For an elementary numeric line type, SUM> sums the line values and assigns the sum to wa>. For non-numeric elementary line types, SUM> has no effect and the work area wa> keeps its current value.
Latest notes: When the AT> control structure is exited, the content of the current table line is reassigned to the work area wa>. ABAP_HINT_END
Example ABAP Coding
Calculation of a sum with SUM> at AT END OF>. The lines of the respective current group level are evaluated. ABEXA 00696 ABAP_EXAMPLE_END
Example ABAP Coding
Calculation of a sum with SUM> at AT LAST>. All lines of the internal table are evaluated. ABEXA 00697 ABAP_EXAMPLE_END
ABAP_EXAMPLE_ABEXA Group Level Processing with Totals> ABAP_EXAMPLE_END
Runtime Exceptions
Catchable Exceptions CX_SY_ARITHMETIC_OVERFLOW>>
Reason for error:
Overflow when calculating totals
Runtime error:
ADDF_INT_OVERFLOW>
Reason for error:
Value too large when calculating totals in internal table, field too small
Runtime error:
SUM_OVERFLOW>
Non-catchable Exceptions
Reason for error:
The statement SUM> was used outside a LOOP> processing of an internal table.
Runtime error:
SUM_NO_INTERNAL_TABLE>
Reason for error:
The statement SUM> was used within a LOOP> processing belonging to another ABAP program.
Runtime error:
SUM_ON_FOREIGN_INTERNAL_TABLE>
Reason for error:
The statement SUM> was used within a loop starting with LOOP ... ASSIGNING>.