02-07-2011 9:52 AM
Hi to all,
Suppose a database table contain records for every customer for credit and debit amount and total field.
.
Customer1 credit debit
015 100 0
015 0 50
Total = - 50
Customer2 credit debit
16 0 200
16 50 0
16 0 0
Total = 150
Customer3 credit debit
10 10 10
10 0 0
Total = 10
Customer credit debit
21 5 0
Total = -5
I need to display total for every customer wise which are > 0.
Only positive total need to display, negative should not be display.
The code is written:
Data: l_v_customer type itab-customer_no.
l_v_total type itab-total.
Sort itab by customer_no.
l_v_total = 0.
Loop at itab into wa.
if sy-tabix = 1.
l_v_customer = wa-customer_no.
endif.
if l_v_customer = wa-customer_no.
l_v_total = l_v_total + wa-total.
else.
if l_v_total LT '0'.
Delete itab where custome_no = l_v_customer.
endif.
l_v_customer = wa-customer_no.
l_v_total = wa-total.
endif.
endloop.
This code is not giving correct result.
Please can any one suggest me correct code to display total > 0 for every customer.
I shall be thankful to you for this .
Regards
Pavneet Rana
Edited by: pavneet rana on Feb 7, 2011 2:59 PM
02-08-2011 8:14 AM
HI,
Try this.
Data: w_total like wa-total value 0.
w_customer like wa-customer.
sort itab by customer.
loop at itab into wa.
w_customer = wa-customer.
w_total = w_total + wa-total.
at end of customer.
if w_total <= 0.
delete itab WHERE customer = w_customer.
endif.
clear: w_total,w_customer.
endat.
ENDLOOP.
02-08-2011 12:44 AM
Hi Pavneet,
Probably the easiet way is to use the COLLECT instead of the APPEND statement when you add the data to the internal table. In this way you end up with an unique record for each customer and their corresponding credit and debit. After this loop through this internal table and purge every record for which the credit is greater than the debit value.
So in your example you would have an internal table of:
015 100 50
016 50 200
010 10 10
resulting in a display of customers.
016 50 200
010 10 10
* Fill itab
wa_customer_no = 015.
wa_credit = 100
wa_debit = 50
Collect wa to itab. clear wa.
....
....
Data: l_v_customer type itab-customer_no.
Sort itab by customer_no.
Loop at itab into wa.
if wa-credit gt wa-debit.
Delete itab where customer_no = wa_customer.
endif.
endloop.
Kind regards,
Robert
02-08-2011 4:07 AM
Thanks for reply,
but i need to deleted internal table based on total which are greater than 0.
and it should check with next customer for total value.
Please can you provide me solution for that.
I shall be thankful to you for this.
Regards
Pavneet Rana
02-08-2011 4:55 AM
hi maybe u can use this,
when you have get all the total for all your customer in itab.
DELETE itab WHERE total GT 0.
that syntax will delete data from your internal table when total greter than 0.
or you can change GT with NE.
02-08-2011 5:15 AM
Thanks for reply,
debit credit total
customer1 10 50 40
customer1 0 50 50
debit credit total
customer2 10 0 -10
customer2 0 0 0
I need that for every customer it should calculate sum of total > 0, and display.
can you just give me logic for that.
I shall be thankfull to you for this.
Regards
Pavneet Rana
02-08-2011 6:29 AM
you have to COLLECT your itab intu another itab
for example
LOOP AT itab.
COLLECT itab INTO itab2.
ENDLOOP.
so your itab2 should like this:
debit credit total
customer1 10 100 90
debit credit total
customer2 10 0 -10
so, in itab2 you can delete customer when total lower than 0 using DELETE syntax.
i hope this can solve your problem
02-08-2011 8:14 AM
HI,
Try this.
Data: w_total like wa-total value 0.
w_customer like wa-customer.
sort itab by customer.
loop at itab into wa.
w_customer = wa-customer.
w_total = w_total + wa-total.
at end of customer.
if w_total <= 0.
delete itab WHERE customer = w_customer.
endif.
clear: w_total,w_customer.
endat.
ENDLOOP.