Application Development 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: 

Logic to calculate moth to date sales

Former Member
0 Kudos

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

1 ACCEPTED SOLUTION

Former Member
0 Kudos

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

5 REPLIES 5

Former Member
0 Kudos

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 Kudos

Thank you Vijay

0 Kudos

Vijay,

If I have to compare two or more fields..

AT NEW F1 F2 .. . can we do that? I'm getting an error.

Thanks,

PV

0 Kudos

AT NEW F1.

ENDAT.

AT NEW F2.

ENDAT.

You can proceed like this.

AT NEW F1 F2 -->u cannot do this

Br,

Vijay.

Former Member
0 Kudos

Can any one help me with the logic to year to date sum

I have an internal table

F1 F9 F2 Date Sales

A X G 10/10 1

A X G 10/11 2

A X G 10/12 3

A Y G 10/10 10

A Y G 10/11 11

Expected output:

A X G 10/10 1

A X G 10/11 1+2 = 3

A X G 10/12 123 = 6

A Y G 10/10 10

A Y G 10/11 10+11 =21

Can any tell me how to do this.

Earlier I got a reply with events in internal table. But unfortunately I cannot check for multiple columns at the same time.

Thanks.

DATA : BEGIN OF ITAB OCCURS 0,

F1,

f9,

F2(6),

F3 TYPE I ,

END OF ITAB.

DATA : GV_FLAG, V_SUM TYPE I .

ITAB-F1 = 'A'. ITAB-F9 = 'X'. ITAB-F2 = '10/10'. ITAB-F3 = 1. APPEND ITAB. CLEAR ITAB.

ITAB-F1 = 'A'. ITAB-F9 = 'X'. ITAB-F2 = '10/11'. ITAB-F3 = 2. APPEND ITAB. CLEAR ITAB.

ITAB-F1 = 'A'. ITAB-F9 = 'Y'. ITAB-F2 = '10/13'. ITAB-F3 = 3. APPEND ITAB. CLEAR ITAB.

ITAB-F1 = 'A'. ITAB-F9 = 'Y'. ITAB-F2 = '10/14'. ITAB-F3 = 4. APPEND ITAB. CLEAR ITAB.

ITAB-F1 = 'B'. ITAB-F9 = 'Z'. ITAB-F2 = '10/7'. ITAB-F3 = 10. APPEND ITAB. CLEAR ITAB.

ITAB-F1 = 'B'. ITAB-F9 = 'Z'. ITAB-F2 = '10/8'. ITAB-F3 = 20. APPEND ITAB. CLEAR ITAB.