Code: Alles auswählen.
DATA: lt_input TYPE ...,
...,
lt_output TYPE ...,
lv_omeng TYPE vbbe-omeng.
" get data ...
" groups by VBELNR
LOOP AT lt_input ASSIGNING FIELD-SYMBOL(<fs_vbel>) GROUP BY <fs_vbel>-vbelnr ASCENDING.
"group by POSNR
LOOP AT GROUP <fs_vbel> ASSIGNING FIELD-SYMBOL(<fs_pos>) GROUP BY <fs_pos>-posnr ASCENDING.
CLEAR lv_omeng.
" add up value of OMENG within group
LOOP AT GROUP <fs_pos> ASSIGNING FIELD-SYMBOL(<fs_sl>).
ADD <fs_sl>-omeng TO lv_omeng.
ENDLOOP.
" append aggregated structure to output table
APPEND VALUE #( vbeln = <fs_sl>-vbeln posnr = <fs_sl>-posnr slno = 1 omeng = lv_omeng ) TO lt_output.
ENDLOOP.
ENDLOOP.
" do something...
Code: Alles auswählen.
DATA: lt_output TYPE HASHED TABLE OF ... WITH UNIQUE KEY vbelnr posnr,
....
" get data ...
LOOP AT lt_input INTO ls_input.
" new line for each key pair, sums for SLNO and OMENG
COLLECT ls_input INTO lt_output.
ENDLOOP.
" correct the SLNO value
LOOP AT lt_output ASSIGNING FIELD-SYMBOL(<fs_output>).
<fs_output>-slno = 1.
ENDLOOP.
" do something ...