Get Example source ABAP code based on a different SAP table
• LOOP AT GROUP ABAP Statement
LOOP AT GROUP> Short Reference >
ABAP_SYNTAX LOOP AT GROUP group result>> $[ WHERE log_exp>$] $[ GROUP BY ...>$].> ...> ENDLOOP.>
ABAP Addition ... WHERE log_exp>
What does it do? Member loop across the lines of a group within the group loop> in the grouping> of internal tables. This loop is only possible within a LOOP>> across an internal table with the addition GROUP BY>>,
for which the internal table itab> is specified directly as a data object and not as the result of a call or expression,
in which the addition WITHOUT MEMBERS> is not used. group> is used to specify the group across which the member loop passes. The target object must be specified that is defined in the output behavior group_result >> of the group loop and bound to the group:
In the representative binding, this is a representative specified in the output behavior result>>.
In the group key binding, this is a data object or field symbol specified in the output behavior group_result>>. The member loop across the current group is executed just like a regular LOOP>> across a standard table with the line type of itab> which contains the lines of the group. Both variants are possible:
Loop across lines> without the addition GROUP BY>.
Loop across groups> with the addition GROUP BY>. The second option enables further groupings of existing groups. System Fields> The statement LOOP AT GROUP> sets the value of the system field sy-tabix> in the member loop to the value that would be set for the current line in the LOOP> without grouping. A member loop always sets the system field sy-subrc> to 0.
Latest notes:
Despite the fact that there is always only one grouping for a single LOOP>, it is still necessary to specify the group group> explicitly, since multiple groups can be accessed in nested LOOP> statements.
group> expects the precise name specified in the output behavior, namely a field symbol with angle brackets specified after ASSIGNING > and a data reference variable without dereferencing operator -> > specified after REFERENCE INTO>.
The statement LOOP AT GROUP> can only be listed within a loop defined using LOOP AT ... GROUP BY> >, since the name for the group defined using its output behavior> is only valid here. LOOP AT GROUP> is in particular not possible in procedures called from a group loop, even if the data object or field symbol defined by the output behavior can be accessed here.
Despite the syntax and semantics of LOOP AT GROUP> being the same as a regular nested loop, the way the lines of the group are actually accessed is optimized. This exploits the internal variant of the assignment of the lines to their group.
A loop LOOP AT GROUP> does not allow group level processing> with the statement AT>>.
A group loop does not create any empty groups, which means that a member loop is always passed as a rule. Only WHERE> conditions can be used to prevent members of a group from being processed. Internally, however, this is not detected until the start of the first loop pass, which means that sy-subrc> is set to 0 in this case as well.
The statement LOOP AT GROUP> corresponds to the expression FOR ... IN GROUP>>. This means its functions can often be expressed more elegantly using table comprehensions> or table reductions>. NON_V5_HINTS ABAP_HINT_END
ABAP_EXAMPLE_VX5 Member loop in a group loop, where the flight numbers belonging to an airline are grouped together in a string. ABEXA 00385 ABAP_EXAMPLE_END
ABAP_EXAMPLE_VX5 The following example shows each of the six different syntax methods of specifying a group in a member loop:
Work area wa> of the LOOP> in a representative binding>.
Field symbol <(><)>> of the LOOP> in a representative binding>.
Data reference variable dref> of the LOOP> in a representative binding>.
Work area group> of the group loop in a group key binding>.
Field symbol group> of the group loop in a group key binding>.
Data reference variable group_ref> of the group loop in a group key binding>. ABEXA 00386 ABAP_EXAMPLE_END
ABAP Addition
What does it do? The lines read from the group can be restricted using a static WHERE> condition>. The syntax and semantics are the same as in a LOOP> across an internal table with the line type of itab>.
Latest notes: The additions USING KEY>>, FROM>>, TO>>, and a dynamic WHERE> condition cannot be specified after LOOP AT GROUP>. NON_V5_HINTS ABAP_HINT_END
ABAP_EXAMPLE_VX5 Like the example above, but with a restricted WHERE> condition for the member loop. ABEXA 00387 ABAP_EXAMPLE_END