Summarize groups without depending on row adjacency

A report needs a count per carrier. LOOP AT ... GROUP BY forms groups by a key even if matching rows are not adjacent in the original table. You can bind group-key values and, when needed, loop through the members.

Bind a key and the group size

LOOP AT dispatches INTO DATA(dispatch)
  GROUP BY ( carrier = dispatch-carrier size = GROUP SIZE )
  INTO DATA(carrier_group).
  DATA(result) = carrier_group-size.
ENDLOOP.

Each group iteration exposes one carrier_group; GROUP SIZE supplies its member count. To process each original row within the group, add LOOP AT GROUP carrier_group INTO DATA(member). If you only need the group key and aggregate metadata, omit member processing.

Grouping syntax has several variants and release constraints. This original example demonstrates the idea; consult the target release documentation before adapting it. For simpler totals or one row-by-row action, LOOP AT, REDUCE, or ABAP SQL aggregation may be easier to review.

Sources

Developer practice · ABAP

Practice: count rows inside each carrier group

Group the dispatches by carrier and put the current group's size in result.

Choose your ABAP environment

This choice changes the output pattern checked here: WRITE belongs in a classic executable report, while out->write( ) uses the supplied output reference in an ABAP Cloud class-run method. It does not switch the language version of the other code; check release and API availability in your target system.

Complete the task and include the output statement shown for your selected environment. Variable names can differ if you use them consistently. This browser checker checks structure only; it does not compile or run ABAP.

0 required structures detected · 0 checks