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

sum amount

Former Member
0 Likes
1,630

HI

i use this part of code:

loop at i_mapping into wa.
  if wa-xblnr ne m_xblnr and wa-mwskz ne m_mwskz.
        clear : wa1.
  move m_xblnr to wa1-xblnr.
        move m_mwskz to wa1-mwskz.
        move m_net   to wa1-znet.
        append wa1 to i_new.
        clear m_net.
   endif.
  append wa to i_new.
  add wa-znet to m_net.
  move wa-xblnr to m_xblnr.
  move wa-mwskz to m_mwskz.
endloop.

clear : wa1.
move m_xblnr to wa1-xblnr.
move m_mwskz to wa1-mwskz.
move m_net   to wa1-znet.
append wa1 to i_new.

this appends the i_mapping to i_new and appends some new lines with the summation of znet by xblnr.

i want not to sum only by xblnr but with xblnr mwskz.

to be more clear if the xblnr and mwszk in first line for example is equal with the third ( let's say that is the last line ) then i want to append a new line (forth line) with the summation of znet of first and third line.

13 REPLIES 13
Read only

Former Member
0 Likes
1,529

Try this

the itab1 has the out put

data : BEGIN OF itab OCCURS 0,

field1 type i,

field2 type i,

field3 type i,

end of itab.

DATA itab1 LIKE HASHED TABLE OF itab

WITH UNIQUE KEY field1 field2.

itab-field1 = 11.

itab-field2 = 10.

itab-field3 = 10.

append itab.

itab-field1 = 11.

itab-field2 = 20.

itab-field3 = 20.

append itab.

itab-field1 = 12.

itab-field2 = 10.

itab-field3 = 20.

append itab.

itab-field1 = 12.

itab-field2 = 10.

itab-field3 = 30.

append itab.

loop at itab.

collect itab into itab1.

endloop.

output.

11 10 10

11 20 20

12 10 50

Read only

Former Member
0 Likes
1,529

Hi,

Check the IF condition


sort <first itab> by xblnr mwskz.
if wa-xblnr ne m_xblnr or wa-mwskz ne m_mwskz

This will insert the summary record for each change of xblnr or mwskz. If you want only summary records use the collect statement.

Regards

Vinod

Read only

Former Member
0 Likes
1,529

Hi,

Before loop at i_mapping into wa.

sort i_mapping by XBLNR MWSKZ.

Regards

Dillip Sahoo

Read only

Former Member
0 Likes
1,529

i have tried everything but it works only for xblnr . what about the combination of xblnr and mwskz.

Read only

0 Likes
1,529

Have you changed the AND condition to OR?

Regards

Vinod

Read only

0 Likes
1,529

yes. it is better but appends a line without doing summation.

if in first itab there is no line to sum ( unique xblnr mwskz) then i dont want to add an extra line.

Edited by: antonis nezos on May 11, 2010 2:37 PM

Read only

0 Likes
1,529

Hi, add a counter variable to check the same

data : m_cnt(5) type n value 0. "added"
loop at i_mapping into wa.
  if wa-xblnr ne m_xblnr and wa-mwskz ne m_mwskz.
        if m_cnt gt 1.          " added"
        clear : wa1.
        move m_xblnr to wa1-xblnr.
        move m_mwskz to wa1-mwskz.
        move m_net   to wa1-znet.
        append wa1 to i_new.
        clear m_net, m_cnt .   "added"
      endif.                       "added"
   endif.
  append wa to i_new.
  add wa-znet to m_net.
 add 1 to m_cnt.   "added"
  move wa-xblnr to m_xblnr.
  move wa-mwskz to m_mwskz.
endloop.
 
if m_cnt gt 1. "added"
clear : wa1.
move m_xblnr to wa1-xblnr.
move m_mwskz to wa1-mwskz.
move m_net   to wa1-znet.
append wa1 to i_new.
endif.   "added"

Regards

Vinod

Edited by: Vinod Kumar on May 11, 2010 5:12 PM

Edited by: Vinod Kumar on May 11, 2010 5:14 PM

Read only

0 Likes
1,529

THANK YOU!!!

Edited by: antonis nezos on May 11, 2010 3:24 PM

Read only

0 Likes
1,529

i noticed that sums and the lines with different mwskz.

the number of lines is correct but not the summation.

Edited by: antonis nezos on May 11, 2010 3:25 PM

Read only

0 Likes
1,529

i noticed that sums and the lines with different mwskz.

the number of lines is correct but not the summation.

any ideas?

Read only

0 Likes
1,529

Hi,

Can you explain with sample output ?

Regards

Vinod

Read only

deepak_dhamat
Active Contributor
0 Likes
1,529

what is data type of wa1-mwskz

Regards

Deepak.

Read only

deepak_dhamat
Active Contributor
0 Likes
1,529

hi,

change data of wa1-mwskz to character

then loop internal table

collect into another other internal table of same type

endloop.

and you will get your desired result .

Regards

Deepak.