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 with Nested Groups
This example demonstrates nested groups in control level processing in internal tables.
Other versions:
7.31 | 7.40 | 7.54
Source Code
TYPES: BEGIN OF group,
fldate TYPE sflight-fldate,
seatsocc TYPE sflight-seatsocc,
END OF group.
DATA: sflight_tab TYPE SORTED TABLE OF sflight
WITH UNIQUE KEY carrid connid fldate,
group TYPE TABLE OF group WITH EMPTY KEY.
DATA(display_members) = abap_false.
cl_demo_input=>request( EXPORTING text = `Display Group Members?`
CHANGING field = display_members ).
DATA(out) = cl_demo_output=>new( ).
SELECT *
FROM sflight
INTO TABLE @sflight_tab.
LOOP AT sflight_tab INTO DATA(sflight_wa).
AT NEW connid.
out->next_section( |{ sflight_wa-carrid } | &&
|{ sflight_wa-connid }| ).
ENDAT.
group = VALUE #( BASE group
( CORRESPONDING #( sflight_wa ) ) ).
AT END OF connid.
IF to_upper( display_members ) = abap_true.
out->write( group ).
ENDIF.
CLEAR group.
SUM.
out->write( |Sum: | &&
|{ sflight_wa-seatsocc }| ).
ENDAT.
AT END OF carrid.
SUM.
out->line(
)->write( |Carrier Sum: | &&
|{ sflight_wa-seatsocc }|
)->line( ).
ENDAT.
AT LAST.
SUM.
out->write( |Overall Sum: | &&
|{ sflight_wa-seatsocc }| ).
ENDAT.
ENDLOOP.
out->display( ).
Description
The sorted table sflight_tab
is filled with flight data from the database
table SFLIGHT. The total in question is calculated and displayed at the
end of nested row groups for the columns CARRID and CONNID and at the end of the complete loop. The contents of the rows in a control level can be displayed as an optional.
The executable example Grouping with Nesting
shows how the same function can be provided using the addition GROUP BY
.