‎2012 Apr 26 12:52 AM
| Material | PO | Posting Date | Order Qty | Material Running Sum |
|---|---|---|---|---|
| 123 | 1000 | 12/1 | 10 | 10 |
| 123 | 1001 | 12/2 | 5 | 15 |
| 123 | 1001 | 12/3 | 15 | 30 |
| 123 | 1002 | 12/3 | -5 | 25 |
| 123 | 1002 | 12/4 | 10 | 35 |
| 456 | 1003 | 12/1 | 5 | 5 |
| 456 | 1004 | 12/1 | 15 | 20 |
| 456 | 1004 | 12/2 | 5 | 25 |
Message was edited by: Vinod Kumar
‎2012 Apr 26 2:35 AM
Hi DC,
Yes, its possible in ABAP. Please use the below logic to calculate the running sum of quantity.
LOOP AT ITAB.
lv_sum = lv_sum + itab-qty.
itab-sum = lv_sum.
MODIFY itab.
AT END OF matnr.
CLEAR lv_sum.
ENDAT.
ENDLOOP.
I tried this example, its calculating the running sum correctly. Check it..
‎2012 Apr 26 2:53 AM
Hi,
Instead of additional loop, you can do it while filling the final output table it self. but it depends on which table data you are using and filling the output table, if that table has MATNR as first column then you can use the same logic as Lakshmi proposed for calculation but MODIFY statement is not required, just clear the LV_SUM in AT END OF matnr.
If the MATNR field is not the first field, you can use the logic suggested by Lakshmi, below is similar to that one without MODIFY statement.
FIELD-SYMBOLS : <fs_final> TYPE ty_final.
LOOP AT i_final ASSIGNING <fs_final>.
v_sum = v_sum + <fs_final>-qty.
<fs_final>-sum = v_sum.
AT END OF matnr.
CLEAR : v_sum.
ENDAT.
ENDLOOP.
Thanks & Regards
Bala Krishna