Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Logic to calculate moth to date sales

Can any one provide me the logic hot to calculate

I have the follwoing in internal table 1:

Comp Date Amount

A 10/10 1

A 10/11 2

A 10/13 3

B 10/7 10

B 10/8 20

Final out put should be month to data sum.

A 10/10 1

A 10/11 1+2 = 3

A 10/13 123

B 10/7 10

B 10/8 10+20

Can any one tell me how to do this. It looks like recursion. How to do this in ABAP

Tags:
Former Member
Former Member replied

its simple ..

execute the logic ..

data : begin of itab occurs 0,

f1,

f2(6),

f3 type i ,

end of itab.

data : gv_flag, v_sum type i .

itab-f1 = 'A'. itab-f2 = '10/10'. itab-f3 = 1. append itab. clear itab.

itab-f1 = 'A'. itab-f2 = '10/11'. itab-f3 = 2. append itab. clear itab.

itab-f1 = 'A'. itab-f2 = '10/13'. itab-f3 = 3. append itab. clear itab.

itab-f1 = 'B'. itab-f2 = '10/7'. itab-f3 = 10. append itab. clear itab.

itab-f1 = 'B'. itab-f2 = '10/8'. itab-f3 = 20. append itab. clear itab.

SORT ITAB BY F1.

LOOP AT ITAB.

AT NEW f1.

gv_flag = 'X'.

endat.

if gv_flag = 'X'.

v_sum = v_sum + itab-f3.

endif.

write :/ itab-f1 , itab-f2, v_sum.

at end of f1.

clear : gv_flag , v_sum.

endat.

ENDLOOP.

br ,

vijay

0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question