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

Summing the internal table values

Former Member
0 Likes
656

Hi Experts,

I have requirement in report to add the values in the internal table based on document no.

for example

Document no date Amount Exchange Rate

190000012 05.04.2009 100 1

190000012 05.04.2009 200 1

190000012 05.04.2009 300 1

190000013 05.04.2009 100 1

190000013 05.04.2009 200 1

190000014 05.04.2009 100 1

If i use Collect or On change statements , the exchange rate is also adding

Document no date Amount Exchange Rate

190000012 05.04.2009 600 3

190000013 05.04.2009 300 2

190000014 05.04.2009 100 1

But i want to add only the amount field not the exchange rate .Please suggest me the best solutions.

I want to display as

Document no date Amount Exchange Rate

190000012 05.04.2009 600 1

190000013 05.04.2009 300 1

190000014 05.04.2009 100 1

Thanks in advance

satish

6 REPLIES 6
Read only

Former Member
0 Likes
634

Define the exchange rate as char in your internal table and keep doing COLECT.

Issa

Read only

BH2408
Active Contributor
0 Likes
634

HI ,

Collect statement will add the all interger fields, So better declare the exchange rate field as the CHAR .

Regards,

Bharani

Read only

Former Member
0 Likes
634

Try this logic it will work.Itab and Itab2 are of same structure.

Sort itab by documentno.
Loop at itab.
itab2-total = itab2-total + itab-total.
Move : itab-documentno to itab2-documentno,
           itab-date to itab2-date,
           itab-exchange to itab2-exchange.

AT END OF documentno.
append itab2.
clear itab2-total.
ENDAT.
Endloop.

Regards,

Gurpreet

Read only

Former Member
0 Likes
634

You can use COLLECT statement

if you are using at end control statement then make sure document number if your first field.

or what you can do is apply this logic!

tempdocno like itab-documentno.
Sort itab by documentno.
Loop at itab.
  if itab-documentno eq tempdocno or sy-tabix eq 1. " check this if and endif.
    itab2-total = itab2-total + itab-amount.
    itab2-documentno = itab-documentno.
    itab2-date = itab-date.
    itab2-exchange = itab-exchange.
  else.
    append itab2.
    clear itab2-total.
  endif.
  tempdocno = itab-documentno.
Endloop.

Regards,

Lalit Mohan Gupta.

Read only

Former Member
0 Likes
634

hi,

check this

Sort itab by documentno.

Loop at itab1.

on change of itab1-dcno.

clear total.

move itab1-docno to itab2-docno.

itab2-total = itab-amont.

move itab1-total to itab2-total.

move itab1-date to itab2-date.

move itab1-rate to itab2-rate.

flag = ' '.

append itab2.

clear itab2.

else.

itab2-total = itab2-total + itab-amont.

endon

Endloop.

it will work for adjest append statement according to the out put .

~linganna

Read only

0 Likes
634

Hi Experts,

Thanks a lot for your suggestions. It is solved.

Regards,

Satish