I'm looking for the equivalent of the AT LAST statement within the LOOP AT ... GROUP BY statement.
I'm looping using group by, and for performance reasons, I execute a call method every few groups, when a certain amount of records has been accumulated into an internal table. But I would like to add an extra condition to run this call at the end of the loop, if I'm in the last group.
Below I wrote a piece of executable code simulating my problem, I would like to process my last material before exiting the loop.
constants: processing_size_threshold type i value 10.
types: begin of ty_material,
material_num type c length 3,
end of ty_material.
data: materials type standard table of ty_material,
materials_bom type standard table of ty_material.
materials = value #( for i = 1 then i + 1 while i <= 3
( material_num = conv #( i ) ) ).
loop at materials reference into data(material_grp) group by material_grp->material_num.
loop at group material_grp reference into data(material).
materials_bom = value #( base materials_bom (
lines of value #( for j = 1 then j + 1 while j <= 5
( material_num = |{ material->material_num }{ j }| ) ) ) ).
endloop.
"The 2nd condition of this IF is what I'm not able to figure out, I need material 3 BOM to be processed here
if lines( materials_bom ) >= processing_size_threshold. "or group_num = last_group.
"me->process_boms(materials_bom).
clear materials_bom.
endif.
endloop.