2008 Apr 08 10:08 AM
I have created an internal table which has values BP number, Contract Account and amount paid. i would like to add the amounts paid per business partner and per contract account and only display the total amount paid per business partner and per contract account. may i have the code to make the addition of the amounts in an internal table.
2008 Apr 08 10:18 AM
hi...
at first wat u must do is make sure dat ur int table structure has the BP no 1st ,den the contract no and last the amt paid.
if the struc is not lik dis the following code wont work.
and also declare another int table with de same structure as de previous one.
code-
1st sort the int table by BP no and contract no in ascending order.
loop at ITAB.
move ITAB to ITAB1.
at end contractno.
sum.
ITAB1-contractno = ITAB-contractno.
endat.
endloop.
now ur ITAB1 will contain wat u require.
reward points if useful.
Regards
Winnie
2008 Apr 08 10:11 AM
2008 Apr 08 10:18 AM
hi...
at first wat u must do is make sure dat ur int table structure has the BP no 1st ,den the contract no and last the amt paid.
if the struc is not lik dis the following code wont work.
and also declare another int table with de same structure as de previous one.
code-
1st sort the int table by BP no and contract no in ascending order.
loop at ITAB.
move ITAB to ITAB1.
at end contractno.
sum.
ITAB1-contractno = ITAB-contractno.
endat.
endloop.
now ur ITAB1 will contain wat u require.
reward points if useful.
Regards
Winnie
2008 Apr 08 10:31 AM
Hello,
So what was meant is that for the same business partners and same Contract account numbers the amount should get added.....
do the following...imagine that you have data in int_tab with 3 fields...Declare int_tab1 as the same internal table type
Sort int_tab by BP Contract_AC.
loop at int_tab into workarea.
collect workarea to int_tab1.
endloop.
Collect statement compares the "BP" and "Contract A/C"
and for the same BP and contractA/C number it adds and appends..if an entry exists in int_tab1 it adds the amount only
eg:
BP | CAno: | Amount
A | 23A | 100
A | 23A | 50
A | 24A | 11
B | 23A | 12
after the collect statement..internal table contains
A | 23A | 150
A | 24A | 11
B | 23A | 12
but it will work only if int_tab contais 3 fields as mentioned..if more fields are there which are non-numeric it will compare that also...
in addition to it also check if the contract Account number is getting added by putting a breakpoint in the code..if so... there are 2 options
(1) Declare a new internal table and pass the field contract number as a character....and use collect on the new internal table..so the contract account number will not get added...
or
instead of collect statement use loops and other logic to suit your requirement
Reward if helpful
Regards
Byju
2008 Apr 08 10:37 AM
Hi,
One way of doing this is by Collect statement as mentioned in previous post.
Other way is
Suppose itab is your internal table with BP no and amount.
Do like this:
make another internal table of same type itab1.
sort itab by BP no.
data : l_bp type bu_partner.
read table itab index 1.
l_bp = itab-partner.
loop at itab.
if itab-partner eq l_bp.
sum = itab-amount.
itab1-sum = sum + itab-sum.
itab1-partner = itab-partner
else.
append itab1.
l_bp = itab-partner.
sum = itab-amount.
itab1-sum = sum + itab-sum.
itab1-partner = itab-partner.
endif.
append itab1
endloop.
Hope this helps.
regards
Sourabh.