Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Running Sum using SAP Program

Former Member
0 Likes
1,119
Hello ,
I am trying to create a column which can return Running Sum of Quantity.
Wondering whether it is possible and how using ABAP?, I know i t can be done in BOBJ/Crystal but the requirement is to achieve in BW.
I have Input from a BW DSO1/Table1: Material, PO, Posting Date, Order Qty.
Output into an other BW DSO2/Table2:  Material, PO, Posting Date, Order Qty, MaterialRunningSum.
Example Data:
MaterialPOPosting DateOrder QtyMaterial Running Sum
123100012/11010
123100112/2515
123100112/31530
123100212/3-525
123100212/41035
456100312/155
456100412/11520
456100412/2525
Your help would be appreciated!
Thanks in advance,
DC
Moderator message : Not enough re-search before posting, discussion locked.

Message was edited by: Vinod Kumar

2 REPLIES 2
Read only

Former Member
0 Likes
569

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..

Read only

former_member585060
Active Contributor
0 Likes
569

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