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: 

Need Summary from internal table

Former Member
0 Kudos

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

7 REPLIES 7

Former Member
0 Kudos

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.

anuj_srivastava
Active Participant
0 Kudos

Hi ,

you can use AT END OF statement for summing up the entries according to the field you wanted.

Regards,

Anuj

SuhaSaha
Advisor
Advisor
0 Kudos

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

Former Member
0 Kudos

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

Former Member
0 Kudos

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.

babu_kilari4
Active Contributor
0 Kudos

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.

Former Member
0 Kudos

got idea