Ansicht
Dokumentation

ABAPLOOP_AT_GROUP - LOOP AT GROUP

ABAPLOOP_AT_GROUP - LOOP AT GROUP

General Material Data   Vendor Master (General Section)  
This documentation is copyright by SAP AG.
SAP E-Book

LOOP AT GROUP

Short Reference



LOOP AT GROUP group result $[ WHERE log_exp$] $[GROUP BY ...$].
  ...
ENDLOOP.

Addition:

... WHERE log_exp

Effect

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:

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.

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 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.

Example

Member loop in a group loop, where the flight numbers belonging to an airline are grouped together in a string.

The following example shows each of the six different syntax methods of specifying a group in a member loop:

Addition

... WHERE log_exp

Effect

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.

Note

The additions USING KEY, FROM, TO, and a dynamic WHERE condition cannot be specified after LOOP AT GROUP.

Example

Like the example above, but with a restricted WHERE condition for the member loop.






General Material Data   General Data in Customer Master  
This documentation is copyright by SAP AG.

Length: 8159 Date: 20240426 Time: 211904     sap01-206 ( 113 ms )