01-07-2011 11:49 AM
While creating sales order, i need to calculate materil price per unit.
So i used the formula:
price_per_unit = net_amount / quantity.
i have declared the net amount and price_per_unit like vbap-netpr and quantity like vbap-zmeng.
But i m getting the wrong anwer.
Example : If the Net Price is 3766.19 and quantity = 250 . Price should be 15.016
The I am getting 0.02 as price.
Is it about declaration error?
Thanks in advance.
Ezhil.
01-07-2011 12:05 PM
Hi,
I have tried the below code
data : price_per_unit type vbap-netpr,
net_amount type vbap-netpr,
quantity type vbap-zmeng.
net_amount = '3766.19'.
quantity = '250'.
price_per_unit = net_amount / quantity.
write: price_per_unit.
output is coming as 15.06.(which is correct)
01-07-2011 12:05 PM
Hi,
I have tried the below code
data : price_per_unit type vbap-netpr,
net_amount type vbap-netpr,
quantity type vbap-zmeng.
net_amount = '3766.19'.
quantity = '250'.
price_per_unit = net_amount / quantity.
write: price_per_unit.
output is coming as 15.06.(which is correct)
01-07-2011 2:01 PM
Yes..I also got the correct answer when in code it in separate..if i use the same code in the user exit MV45AFZZ, i am not getting the correct value.
01-07-2011 3:58 PM
You need to adjust for the fixed-point arithmetic setting. You should also be calculating something like this in a pricing formula (where you would also need to make the same adjustment).
01-07-2011 6:59 PM
I am afraid if the calculation is wrong. Net price (netwr) will be effected by different condition records in your pricing procedure. Condition type NETP will hold the net price.. you need to verify with your functional counter part on this.
01-11-2011 10:39 AM
Hi,
I think this is because data types CURR and QUAN. Does anyone know how to convert these datatypes to number data type.
Thanks
01-11-2011 10:58 AM
Hi,
Pass these values to char type values that of the same length of each fields and then do the calcluation.
With Regards,
Sumodh.P
01-11-2011 11:27 AM
Hi,
I tried everything. Everything is working fine in separate programs but not in this user exit. It seems, division is not happening in this include. Could this situation happen?
if so, what is the remedy.
Thanks.
01-11-2011 11:40 AM
Hi,
I created a test include and tried this code. It worked fine. Haven't tried this in MV45AFZZ. Could you paste your piece of code you are using inside the exit.
01-11-2011 11:44 AM
Hi,
Please paste the entire code what you are doing for this calculation.
With Regards,
Sumodh.P
01-11-2011 11:49 AM
Hi,
Below is the code,
FORM price_check.
DATA: quan TYPE EKPO-MENGE.
DATA: quan1 LIKE vbap-zmeng.
DATA: price LIKE xvbap-netwr.
DATA: amt LIKE xvbap-netwr.
DATA: price_per TYPE p DECIMALS 3.
SELECT SINGLE * FROM ztsd_sal_pr_cntr
WHERE vkorg = vbak-vkorg
AND vtweg = vbak-vtweg
AND prctr = xvbap-prctr
AND matnr = xvbap-matnr.
IF sy-subrc NE 0.
MESSAGE ID 'ZV' TYPE 'E' NUMBER '041'.
ELSE.
* IF ztsd_sal_pr_cntr-kmein NE xvbap-kmein.
IF ztsd_sal_pr_cntr-kmein NE xvbap-vrkme.
quan1 = xvbap-kwmeng.
CALL FUNCTION 'ME_CONVERSION_MEINS'
EXPORTING
i_kumne = xvbap-umvkz
i_kumza = xvbap-umvkn
i_matnr = xvbap-matnr
i_mein1 = xvbap-vrkme
* i_mein1 = xvbap-zieme
i_meins = ztsd_sal_pr_cntr-kmein
i_menge = quan1
IMPORTING
menge = quan
EXCEPTIONS
error_in_conversion = 1
no_success = 2
OTHERS = 3.
IF sy-subrc <> 0.
MESSAGE ID 'ZV' TYPE 'E' NUMBER '042'.
ENDIF.
ELSE.
quan = xvbap-kwmeng.
ENDIF.
IF ztsd_sal_pr_cntr-waerk NE xvbap-waerk.
CALL FUNCTION 'CONVERT_TO_FOREIGN_CURRENCY'
EXPORTING
date = sy-datum
foreign_currency = ztsd_sal_pr_cntr-waerk
* local_amount = XVBAP-NETPR
local_amount = xvbap-netwr
local_currency = xvbap-waerk
IMPORTING
foreign_amount = price
EXCEPTIONS
no_rate_found = 1
overflow = 2
no_factors_found = 3
no_spread_found = 4
derived_2_times = 5
OTHERS = 6.
IF sy-subrc <> 0.
MESSAGE ID 'ZV' TYPE 'E' NUMBER '043'.
ENDIF.
amt = price.
ELSE.
amt = xvbap-netwr.
ENDIF.
price_per = amt / quan.
IF price_per >= ztsd_sal_pr_cntr-min_rate
AND price_per <= ztsd_sal_pr_cntr-max_rate.
ELSE.
MESSAGE ID 'ZV' TYPE 'E' NUMBER '044'.
ENDIF.
ENDIF.
ENDFORM. "price_check
Thanks.
01-11-2011 12:03 PM
What values are you getting for xvbap-kwmeng , price and xvbap-netwr. Are you getting the same as mentioned below:
amt = '3766.19'.
quan = '250'
01-11-2011 12:09 PM
Quan field is also in decimal
Example: 250.000
It has three decimal points
01-11-2011 12:15 PM
Fine...When i tried it in my test include i got the result as :
3766.19 / 250.000 = 15.065
Do you get the same values in your final calculation for net_price amount ?
Edited by: K.Manas on Jan 11, 2011 1:15 PM
01-11-2011 12:30 PM
01-11-2011 12:31 PM
Hi,
Try with the below code.
Data : quan(17) type c,
amt(21) type c,
price_per(21) type c .
Pass the corresponding values to the appropriate field and then do the calculation.
last condense price_per no gaps.
Please try with this code.
With Regards,
Sumodh.P
01-11-2011 12:41 PM
Change your data type decleration as per your requirement to pick correct values. Debug and see where it is placing incorrect values that don't suit with the original/correct values.
Change the variables data types and check. This will solve your issue.
01-11-2011 12:44 PM
Hi,
I tried with the character variables also..it works but not in this include.
01-11-2011 12:54 PM
While debugging what are the values that are you getting for the lines of code marked as red.
FORM price_check.
DATA: quan TYPE EKPO-MENGE.
DATA: quan1 LIKE vbap-zmeng.
DATA: price LIKE xvbap-netwr.
DATA: amt LIKE xvbap-netwr.
DATA: price_per TYPE p DECIMALS 3.
SELECT SINGLE * FROM ztsd_sal_pr_cntr
WHERE vkorg = vbak-vkorg
AND vtweg = vbak-vtweg
AND prctr = xvbap-prctr
AND matnr = xvbap-matnr.
IF sy-subrc NE 0.
MESSAGE ID 'ZV' TYPE 'E' NUMBER '041'.
ELSE.
* IF ztsd_sal_pr_cntr-kmein NE xvbap-kmein.
IF ztsd_sal_pr_cntr-kmein NE xvbap-vrkme.
quan1 = xvbap-kwmeng.
CALL FUNCTION 'ME_CONVERSION_MEINS'
EXPORTING
i_kumne = xvbap-umvkz
i_kumza = xvbap-umvkn
i_matnr = xvbap-matnr
i_mein1 = xvbap-vrkme
* i_mein1 = xvbap-zieme
i_meins = ztsd_sal_pr_cntr-kmein
i_menge = quan1
IMPORTING
menge = quan
EXCEPTIONS
error_in_conversion = 1
no_success = 2
OTHERS = 3.
IF sy-subrc 0.
MESSAGE ID 'ZV' TYPE 'E' NUMBER '042'.
ENDIF.
ELSE.
quan = xvbap-kwmeng. " Need the value of xvbap-kwmeng
ENDIF.
IF ztsd_sal_pr_cntr-waerk NE xvbap-waerk.
CALL FUNCTION 'CONVERT_TO_FOREIGN_CURRENCY'
EXPORTING
date = sy-datum
foreign_currency = ztsd_sal_pr_cntr-waerk
* local_amount = XVBAP-NETPR
local_amount = xvbap-netwr
local_currency = xvbap-waerk
IMPORTING
foreign_amount = price
EXCEPTIONS
no_rate_found = 1
overflow = 2
no_factors_found = 3
no_spread_found = 4
derived_2_times = 5
OTHERS = 6.
IF sy-subrc 0.
MESSAGE ID 'ZV' TYPE 'E' NUMBER '043'.
ENDIF.
amt = price. "If satisfies : what value ?
ELSE.
amt = xvbap-netwr. "If satisfies : what value ?
ENDIF.
price_per = amt / quan.
IF price_per >= ztsd_sal_pr_cntr-min_rate
AND price_per <= ztsd_sal_pr_cntr-max_rate.
ELSE.
MESSAGE ID 'ZV' TYPE 'E' NUMBER '044'.
ENDIF.
ENDIF.
ENDFORM. "price_check
01-11-2011 12:59 PM
Hi,
I tried with the below code inside the include
DATA: price_per TYPE p DECIMALS 3.
DATA: amt1 TYPE p DECIMALS 2.
DATA: quan2 TYPE p DECIMALS 3.
amt = '200.36'.
quan = '100.320' .
price_per = amt1 / quan2.
but this is also not working...it gives 0.000 as a output.
01-11-2011 1:17 PM
>
> Hi,
>
> I tried with the below code inside the include
>
>
> > DATA: price_per TYPE p DECIMALS 3. > DATA: amt1 TYPE p DECIMALS 2. > DATA: quan2 TYPE p DECIMALS 3. > > amt = '200.36'. > quan = '100.320' . > price_per = amt1 / quan2. > >
>
> but this is also not working...it gives 0.000 as a output.
Change this to :
DATA: price_per TYPE p DECIMALS 3.
DATA: amt1 TYPE p DECIMALS 2.
DATA: quan2 TYPE p DECIMALS 3.
amt1 = '200.36'.
quan2 = '100.320' .
price_per = amt1 / quan2.
Check the data decleration as said earlier in my post if the issue exists in the original code. Debug to see where it is changing the values and why?. I assume data decleration is the only part which arise this issue.
Edited by: K.Manas on Jan 11, 2011 2:20 PM
01-11-2011 3:55 PM
Hi,
The issue is solved.
The issue was with Fixed Point arithmetic. This is not checked in the program attributes as it is a include program.
Thanks for all your help
Ezhil.
01-11-2011 11:00 AM
hello guru,
data : price_per_unit type p DECIMALS 2,
net_amount type vbap-netpr,
quantity type vbap-zmeng.
net_amount = '3766.19'.
quantity = '250'.
price_per_unit = net_amount / quantity.
write: price_per_unit.
try like this .
may be help fu lfor you.
thanks,
anji.