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

cumulate the average value

Former Member
0 Likes
708

Hi,

my problem is i have to cumulate the value of 1 and 2 so that first row will have same avg value.. 2 nd row will have sum of first and second value...simliarly thrid row will have sum of seond ans third,............n

for eg.

customer qty cum

aaaaa 100 100

bbbbb 200 300

ccccc 100 400

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
680

Hello

Try this logic:


data: value type i.
loop at itab.
  itab-cum = itab-qty + value.
  modify itab.
  value = itab-cum.
endloop.

Hello

Try this logic:


data: value type i.
loop at itab.
  itab-cum = itab-qty + value.
  modify itab.
  value = itab-cum.
endloop.

3 REPLIES 3
Read only

Former Member
0 Likes
680

Hi,

Please check below code.

Internal table T_TAB is initial table & internal table T_TAB1 is total of current & previous rows.

REPORT ZTEST.

DATA:

b TYPE i,

c TYPE i.

DATA:

BEGIN OF t_tab OCCURS 0,

a TYPE i,

END OF t_tab,

t_tab1 LIKE STANDARD TABLE OF t_tab WITH HEADER LINE.

t_tab-a = 10.

APPEND t_tab.

CLEAR t_tab.

t_tab-a = 20.

APPEND t_tab.

CLEAR t_tab.

t_tab-a = 25.

APPEND t_tab.

CLEAR t_tab.

t_tab-a = 40.

APPEND t_tab.

CLEAR t_tab.

LOOP AT t_tab.

IF sy-tabix EQ 1.

b = t_tab-a.

t_tab1-a = b.

APPEND t_tab1.

CLEAR t_tab1.

ELSE.

c = t_tab-a + b.

t_tab1-a = c.

APPEND t_tab1.

CLEAR t_tab1.

b = t_tab-a.

ENDIF.

ENDLOOP.

Thanks & Regards,

Rajni MV.

Read only

Former Member
0 Likes
681

Hello

Try this logic:


data: value type i.
loop at itab.
  itab-cum = itab-qty + value.
  modify itab.
  value = itab-cum.
endloop.

Read only

Former Member
0 Likes
680

Hi Kavitha,

Below code will work for your requirement,

LOOP AT it_tab INTO wa_tab.
  " w_hold has the value of 'CUM' from previous entry
  "For first entry it will be initial
  wa_tab-cum = wa_tab-qty + w_hold.
  MODIFY it_tab FROM wa_tab TRANSPORTING cum.
  w_hold = wa_tab-cum. "as mentioned earlier CUM value is copied
ENDLOOP.

Hope this helps.

Regards,

Manoj Kumar P