03-26-2009 10:49 AM
hi experts.
i have following case
i have internal table i_detail which contain .
invNo amount Customer
1 12 A
2 5 A
3 15 B
4 10 C
now i want summary like that according to customer
Customer Amount NoOfInvoices.
A 17 2
B 15 1
C 10 1
ow can i process loop or any thing else which give me summary in another internal table.
Edited by: HarrisAhmed on Mar 26, 2009 11:49 AM
Edited by: HarrisAhmed on Mar 26, 2009 11:51 AM
Edited by: HarrisAhmed on Mar 26, 2009 11:52 AM
03-26-2009 10:53 AM
first in your internal table customer must be the first column.
then sort your internal table by customer.
loop at i_detail.
v_counter = v_counter + 1.
v_amount = v_amount + i_detail-amount.
at end of customer.
itab-noof invoices = v_counter.
itab-amount = v_amount.
append itab.
clear v_amount.
clear v_counter.
endat.
endloop.
03-26-2009 10:54 AM
Hi ,
you can use AT END OF statement for summing up the entries according to the field you wanted.
Regards,
Anuj
03-26-2009 10:54 AM
Hello Hariss,
Quick question: Can you not make the structure of int. table to:
Customer invNo amount
A 1 12
A 2 5
B 3 15
C 4 10
@ PBS & Anuj: Plz try the code before posting. AT END OF...ENDAT will not behave correctly as per your code.
BR,
Suhas
PS: This will make your code very very easier.
Edited by: Suhas Saha on Mar 26, 2009 11:54 AM
03-26-2009 10:55 AM
Hi,
You can use the following logic:
if you need to print directly...
data: wa_detail like line of i_detail.
data: wa_output like wa_detail.
data: count type i.
loop at i_detail into wa_detail.
on change of wa_detail-customer.
if sy-tabix <> 1.
write: / wa_output-customer, wa_output-amount, count.
clear count.
clear wa_output.
endif.
wa_output-customer = wa_detail-customer.
Endon.
count = count + 1.
wa_output-amount = wa_output-amount + wa_detail-amount.
at last.
write: / wa_output-customer, wa_output-amount, count.
clear count.
clear wa_output.
endat.
endloop.
Best Regards,
Suresh
03-26-2009 10:58 AM
Hi,
First you need to SORT your internal table by CUSTOMER
Then create another internal table where you store your added up amount and total no of inv through 2 variables for same CUSTOMER
You may also DELETE ADJACENT DUPLICATES if required.
Regards.
03-26-2009 11:07 AM
Use Collect statement to add up the data.
Use your own logic to count the number of entries for the same customer.
Its so simple. You got to sort the table first.
03-28-2009 6:56 AM