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.
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
Write your solution, then check its structure.
One possible solution
TYPES: BEGIN OF ty_dispatch,
dispatch_id TYPE string,
carrier TYPE string,
END OF ty_dispatch.
TYPES ty_dispatches TYPE STANDARD TABLE OF ty_dispatch WITH EMPTY KEY.
DATA(dispatches) = VALUE ty_dispatches( ( dispatch_id = 'D-1701' carrier = 'NORTH' ) ( dispatch_id = 'D-1702' carrier = 'NORTH' ) ( dispatch_id = 'D-1703' carrier = 'EAST' ) ).
LOOP AT dispatches INTO DATA(dispatch)
GROUP BY ( carrier = dispatch-carrier size = GROUP SIZE )
INTO DATA(carrier_group).
DATA(result) = carrier_group-size.
ENDLOOP.
WRITE result.out->write( result ).These are context-specific output examples. In your own program, use the result variable from your solution and the output mechanism available in that program.