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

Help required with logic

Former Member
0 Likes
441

Moderator message: pleause use a meaningful subject in future

Hi,

I have a custom table which has customer ID field and amount field.

In the report I need to bucket data by amount and no. of customers in that bucket.

For ex: for amount range 1.00 u2013 25.00 there are 100 customers and total amount $1000.00, 25.01 to 50.00 there are 34 customers and total amount $20,000 and so on.

What I am planning to do is fetch records from table into internal table using group by clause,


SELECT CUSTOMER AMOUNT FROM CUSTOMER_FINES INTO TABLE LT_FINES GROUP BY CUSTOMER AMOUNT.

This would bring me in the internal table all customers and their fine. Now what would be the best logic to separate them out into groups.

Approach what I thought of is having two variables for each bucket no_of_customers and total_amount. Then loop through the internal table add If conditions on amount and then accordingly increment no_of_customers for that bucket and add amount to total_amount.

But the internal table is likely to have a lot of records about half a million. Is this a good approach. Can you'll recommend what is the right way to achieve this.

Thanks in advance,

CD

Edited by: Matt on Dec 17, 2009 10:02 AM

Moderator message: pleause use a meaningful subject in future

Hi,

I have a custom table which has customer ID field and amount field.

In the report I need to bucket data by amount and no. of customers in that bucket.

For ex: for amount range 1.00 u2013 25.00 there are 100 customers and total amount $1000.00, 25.01 to 50.00 there are 34 customers and total amount $20,000 and so on.

What I am planning to do is fetch records from table into internal table using group by clause,


SELECT CUSTOMER AMOUNT FROM CUSTOMER_FINES INTO TABLE LT_FINES GROUP BY CUSTOMER AMOUNT.

This would bring me in the internal table all customers and their fine. Now what would be the best logic to separate them out into groups.

Approach what I thought of is having two variables for each bucket no_of_customers and total_amount. Then loop through the internal table add If conditions on amount and then accordingly increment no_of_customers for that bucket and add amount to total_amount.

But the internal table is likely to have a lot of records about half a million. Is this a good approach. Can you'll recommend what is the right way to achieve this.

Thanks in advance,

CD

Edited by: Matt on Dec 17, 2009 10:02 AM

2 REPLIES 2
Read only

prasenjit_sharma
Active Contributor
0 Likes
414

Hi,

do this.

1. create counters for the no of ranges you have say 1.00 u2013 25.00 counter1 total_amt1, 25.01 to 50.00 counter2 total_amt2 etc

2. loop at your internal table

3. check which range the amount falls into using IF statement

4. increment counter* by 1 and add amount to total_amt*

You are done.

Regards

Prasenjit

Read only

matt
Active Contributor
0 Likes
414

Moderator message: pleause use a meaningful subject in future