Skip to content

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 →  Examples of Control Level Processing 

Control Level Processing for Unsorted Tables

This example demonstrates control level processing for an unsorted internal table.

Other versions: 7.31 | 7.40 | 7.54

Source Code

    DATA(out) = cl_demo_output=>new( ).

    out->begin_section(
      `Control Level Processing for Unsorted Table` ).
    DATA group TYPE t_itab.
    LOOP AT itab INTO DATA(wa).
      AT NEW col1.
        CLEAR group.
      ENDAT.
      group = VALUE #( BASE group ( wa ) ).
      AT END OF col1.
        out->write( group ).
      ENDAT.
    ENDLOOP.

    out->next_section(
      `Grouping for Unsorted Table` ).
    LOOP AT itab INTO wa GROUP BY wa-col1.
      group = VALUE #( FOR <wa> IN GROUP wa ( <wa> ) ).
      out->write( group ).
    ENDLOOP.

    out->begin_section(
      `Control Level Processing for Sorted Table` ).
    SORT itab BY col1 ASCENDING.
    LOOP AT itab INTO wa.
      AT NEW col1.
        CLEAR group.
      ENDAT.
      group = VALUE #( BASE group ( wa ) ).
      AT END OF col1.
        out->write( group ).
      ENDAT.
    ENDLOOP.

    out->display( ).

Description

Performs control level processing across an unsorted internal table with the group key col1. Control breaks are produced by each change in the content of this column. A grouping using GROUP BY produces a different result, by comparison, since this grouping is not dependent on the sorting of the internal table. Control level processing for the table sorted by col1 has the same result as the grouping.