‎2021 Nov 23 1:37 PM
is there a better way to do this sum:
LOOP AT lt_mbew INTO DATA(ls_mbew).
lv_sum += ls_mbew-stprs.
ENDLOOP.
Thank you,
‎2021 Nov 23 2:25 PM
Hi Jonathan,
you should check the reduce function:
This is explained in this blog: https://blogs.sap.com/2017/05/25/replace-the-loop-for-reduce-operator/
<fs_ekpo>-netwr = REDUCE netwr( INIT val TYPE netwr
FOR wa IN
FILTER #( it_komv
USING KEY key_kposn
WHERE kposn EQ CONV #( <fs_ekpo>-ebelp ) )
NEXT val = val + wa-kwert ).
Greetings
‎2021 Nov 23 2:25 PM
Hi Jonathan,
you should check the reduce function:
This is explained in this blog: https://blogs.sap.com/2017/05/25/replace-the-loop-for-reduce-operator/
<fs_ekpo>-netwr = REDUCE netwr( INIT val TYPE netwr
FOR wa IN
FILTER #( it_komv
USING KEY key_kposn
WHERE kposn EQ CONV #( <fs_ekpo>-ebelp ) )
NEXT val = val + wa-kwert ).
Greetings
‎2021 Nov 23 2:35 PM
Hi Thorsten,I checked it but how would you write it in this case?
‎2021 Nov 23 3:09 PM
Hi Joinathan,
In your case, it should be:
lv_sum = REDUCE #( INIT val = 0
FOR wa IN lt_mbew NEXT val = val + wa-stprs ).
or with yourtype like num10, or i, ....
lv_sum = REDUCE yourtype( INIT val = 0
FOR wa IN lt_mbew NEXT val = val + wa-stprs ).