ABAP - Keyword Documentation →  ABAP - Reference →  Processing Internal Data →  Internal Tables →  Processing Statements for Internal Tables →  LOOP AT itab →  LOOP AT itab - Basic Form →  AT - Group Level Processing → 

SUM

Quick Reference

Syntax

SUM.

Effect

The statement SUM can only be specified within a loop starting with LOOP, and is only respected within a AT-ENDAT control structure. Prerequisites for using the statement SUM include using the addition INTO in the LOOP statement, and that the specified work area wa is compatible with the row type of the internal table. In addition, SUM cannot be used when the row type of the internal table itab contains components that are tables.

Note

When the AT control structure is exited, the content of the current table row is reassigned to the work area wa.

Example

Calculates a sum with SUM at AT END OF. The rows of the respective current group level are evaluated.

DATA:
  BEGIN OF wa,
    col1 TYPE i,
    col2 TYPE i,
  END OF wa,
  itab LIKE TABLE OF wa WITH EMPTY KEY.

itab = VALUE #( FOR i = 1 UNTIL i > 5
                FOR j = 1 UNTIL j > i
                ( col1 = i col2 = j ) ).

LOOP AT itab INTO wa.
  AT END OF comp2.
    SUM.
    cl_demo_output=>write( wa ).
  ENDAT.
ENDLOOP.
cl_demo_output=>display( wa ).

Example

Calculates a sum with SUM at AT LAST. All rows of the internal table are evaluated.

DATA:
  BEGIN OF wa,
    col      TYPE i,
  END OF wa,
  itab LIKE TABLE OF wa WITH EMPTY KEY.

itab = VALUE #( FOR i = 1 UNTIL i > 10 ( col = i ) ).

LOOP AT itab INTO wa.
  AT LAST.
    SUM.
    cl_demo_output=>display( wa ).
  ENDAT.
ENDLOOP.

Executable Example

Group Level Processing with Totals

Exceptions

Handleable Exceptions

CX_SY_ARITHMETIC_OVERFLOW

Non-Handleable Exceptions