Skip to content

ABAP Keyword Documentation →  ABAP - Reference →  Processing Internal Data →  Internal Tables →  Processing Statements for Internal Tables →  AT - itab 

Control Level Processing

This example demonstrates the control level processing in internal tables.

Other versions: 7.31 | 7.40 | 7.54

Source Code

    DATA: BEGIN OF line,
             col1 TYPE c LENGTH 1,
             col2 TYPE i,
             col3 TYPE i,
          END OF line.

    DATA itab LIKE HASHED TABLE OF line
              WITH UNIQUE KEY col1 col2.

    line-col1 = 'A'.
    DO 3 TIMES.
      line-col2 = sy-index.
      line-col3 = sy-index ** 2.
      INSERT line INTO TABLE itab.
    ENDDO.

    line-col1 = 'B'.
    DO 3 TIMES.
      line-col2 = 2 * sy-index.
      line-col3 = ( 2 * sy-index ) ** 2.
      INSERT line INTO TABLE itab.
    ENDDO.

    SORT itab.

    LOOP AT itab INTO line.
      WRITE: / line-col1, line-col2, line-col3.
      AT END OF col1.
        SUM.
        ULINE.
        WRITE: / line-col1, line-col2, line-col3.
        SKIP.
      ENDAT.
      AT LAST.
        SUM.
        ULINE.
        WRITE: / line-col1, line-col2, line-col3.
      ENDAT.
    ENDLOOP.

Description

A hashed table itab is created, filled with six rows, and sorted. In the LOOP - ENDLOOP, the work area line is used and is displayed for every loop pass. The first field of the primary table key col1 is used for control level processing. The sum of all numerical fields is calculated each time the contents of col1 changes and once for the last table row.