‎2005 Oct 28 5:38 PM
Greetings, I am trying to calculate tax rates for a Purchase
Order by operating as follows:
tables: ekko, ekpo, komv.
data: tax_rate type p decimals 2
... Appropriate looping
tax_rate = komv-kbetr / ( ekpo-netpr * ekpo-menge )
which means:
rate = tax amount / ( net price * quantity )
The value stored in tax_rate is always 0 after executing the code, regardless of the values stored in tables.
The currency type used is such that when I debug the program and visualize the values of kbetr and netpr the value shown is actually the real value divided by 100 and the quantity field has 3 decimal places.
Also when visualizing partial results I get things like this:
data: net_value type p decimals 2.
net_value = ekpo-netpr * ekpo-menge.
when netpr has a value of 97.00 and menge 2.000 the value stored in net_value is 194000.00
Could someone clarify this situation? How do I control the currency conversions and how do I manage P-type variables with different decimal places? Any help is much appreciated.
‎2005 Oct 28 6:04 PM
Hi Sergio,
Probably the Tax % is too low.
Try:
tax_rate = ( komv-kbetr * 100 ) / ( ekpo-netpr * ekpo-menge ).
This should bring up the tax as % and show the digits.
For your second question on net_value:
It depends on how you plan to use. If you want to display it correctly or pass it on, use:
write net_value currency curr.
or
write net_value to var_xxx currency curr.
Regards,
Bhanu
‎2005 Oct 28 8:43 PM
Thank you very much, tried to multiply by 100 but the result is still 0. About the write sentece, it works well, but what I need is to transfer the value to another variable in order to continue a series of calculations needed, is in this case where the problem arises.
Regards,
SAF
‎2005 Oct 28 9:01 PM
Sergio - how are you filling structure KOMV? It's just a structure (not a table). If you don't put a value into komv-kbetr (from say konv-kbetr), the result will be 0.
Rob
‎2005 Oct 28 9:39 PM
Hi Rob, I am filling the structure by fetching records from the database, I checked that komv-kbetr contains a value.
the actual calculation I am doing, by checking in the debugger is:
tax_rate = 31.04 / ( 97.00 * 2.000 )
but the result yields 0 no matter what values I put in the operands, I am suspecting it has to do with the field types and what I am seeing is the output conversion for the fields and the real data stored in the fields are much smaller values.
Data types are as follows:
tax_rate(6) type p decimals 2
kbetr type kbetr curr 11
netpr type bprei curr 11
menge type menge quan 13,3
‎2005 Oct 28 9:59 PM
What happens if you:
TABLES: ekko, ekpo, komv.
DATA: tax_rate TYPE p DECIMALS 2.
komv-kbetr = 3104.
komv-kbetr = komv-kbetr / 100.
ekpo-netpr = 97.
ekpo-menge = 2.
tax_rate = komv-kbetr / ( ekpo-netpr * ekpo-menge ).
I get tax_rate = 0.16.
Rob
‎2005 Oct 28 10:18 PM
Specifically, I get a non-zero tax_rate for:
TABLES: ekko, ekpo, komv, konv.
DATA: tax_rate TYPE p DECIMALS 2,
rate LIKE komv-kbetr.
rate = 3105.
rate = rate / 100.
SELECT kbetr FROM konv UP TO 1 ROWS
INTO komv-kbetr
WHERE kbetr = rate.
ENDSELECT.
SELECT netpr menge FROM ekpo UP TO 1 ROWS
INTO (ekpo-netpr, ekpo-menge)
WHERE netpr = 97.
ENDSELECT.
tax_rate = komv-kbetr / ( ekpo-netpr * ekpo-menge ).
So I think that somehow komv-kbetr is 0 in your program. Did you set a break-point before and after it?
(I changed your values slightly to make sure I retrieved data.)
Rob
‎2005 Oct 28 10:50 PM
Rob, yes, I actually took the values from the debugger. In order to investigate the problem further, I did the following:
DATA: quantity type f,
price type f,
tax type f,
rate_f type f.
... Data Retrieval
MOVE wa_ekpo-menge TO quantity.
MOVE wa_ekpo-netpr TO price.
MOVE wa_komv-kbetr TO tax.
rate_f = tax / ( net * quantity ).
With this, the only way I get the 0.16 rate is dividing quantity / 1000, when moving the value 2.000 into the f variable, it translates into the value 2000.
By modifying the original formula to be:
rate = wa_komv-kbetr / (wa_ekpo-netpr*(wa_ekpo-menge/1000)).
I still get rate = 0.
the only way I obtained the correct value 0.16 is by using:
rate = wa_komv-kbetr100000 / (wa_ekpo-netpr(wa_ekpo-menge)).
since I found that when translating the 97.00 value in netpr into the f variable, it becomes 9700 which is the actual currency value entered for the order.
I found that the currency type for this order is COP instead of USD, it works well with dollars but when working with different currencies the values stored are shifted by 100 or 1000. The question is now: Is there a way to control the way calculations are made according to the currency type?
‎2005 Oct 28 10:59 PM
I think I'm beginning to see. You might be able to use the ratio fields in table TCURR for the currency you are working with.
Rob
‎2005 Oct 31 4:43 PM
Rob, thank yo very much for your answers, all have been very helpful, besides checking the ratio values in the TCURR table, I was able to track down the problem. What was happening was that the fixed point arithmetic option in the program attributes was unchecked, so the interpreter was taking the variables of type p in a very different way than expected (bitwise is my guess), by checking that option all calculations inside the program started to work flawlessly.
This was a very good lesson to learn and I hope this thread will be useful for others as well.
Thanks again and best regards,
Sergio A. Feo
‎2005 Oct 31 5:12 PM