How do I add the values in a field based on the same values in another field using FOR loop?
Types:
Begin of ty_final,
doctype type char5,
posnr type char5,
total type quan5,
End of ty_final.
DATA(lt_final) = VALUE ty_final(
FOR line IN lt_history
WHERE ( hist_type = 'U' )
( doctype = line-hist_type
total = line-quantity
posnr = line-po_item ) ).
What I have in LT_HISTORY:
HIST_TYPE POSNR QUANTITY
U 10 5
U 10 2
U 20 3
U 20 -3
What I need in LT_FINAL:
DOCTYPE POSNR QUANTITY
U 10 7
U 20 0
I am trying to use GROUP BY
to get the sum of the values in TOTAL
field based on POSNR
and DOCTYPE
fields. It's just that I am not sure where exactly I need to add GROUP BY
in my FOR
loop. REDUCE
makes my head spin. So I was trying out as simple as possible.