2011 Dec 21 4:31 PM
I specifically require a FM, for converting a 2 decimal currency value to a 5 decimal currency value for the following format.
I have a variable of type NETWR which is CURR 15 DEC 2
I need to store the same in either packed, character field or even currency will work but that should be of 5 decimal places as I need to display the value for USD5 currency.
For eg I am having a value in the variable of NETWR, 123456789.90
For this scenario i want output as 123456.78990
Write statement and move statement behaves correctly for this. ( we require this)
But main problem arises when my value of NETWR variable will be like 1.09, 21.09 or 221.09
as it stores 0.00109 0.02109 or 0.22109 which is worong and ideally that should be
1.09000, 21.09000 or 221.09000 for such cases in USD5 variable
I have checked By using various existing FM like BAPI_CURRENCY_CONV_TO_EXTERNAL, CURRENCY_AMOUNT_SAP_TO_BAPI , HR_NZ_ROUNDING_DECIMALS but these are not useful for this scenario
Kindly suggest some technique so that i can convert 2 decimal currency to 5 decimal currency.
2011 Dec 21 4:59 PM
data: lv_currency5(15) type p decimals 5.
...
lv_currency5 = <yourstructure>-netwr.
Not very hard is it?
but, actually you're complaing about the way SAP stores some values.... and you want to go FROM 5 to 2.
lv_currency2(15) type p decimals 2.
LV_currency2 = <yourstructure>-netwr * 1000.
would do the trick for you.
Edited by: BreakPoint on Dec 21, 2011 6:03 PM
2011 Dec 21 5:14 PM
Hi Break point,
Thanks for the reply but this is not my requirement, I want to convert a 2 decimal currency to 5 decimal currency.
for example 12345678.90 to 123456.78900 (yes i want this as the object which I have calculates the value and stores in variable type NETWR which is decimal 2 hence i moved the same to packed decimal 5 and I got it correct but on the same note, Its creating problems for 1.09 types of values. as it will store 0.00109 which is not as per my requirement and I want 1.09000 for those cases)
Special conditions required for decimals having length less than or equal to 5
2011 Dec 21 5:49 PM
Hi Bhavi
who in this SAP world is asking about this requirement... who ever is asking this is a wrong real time situation.. please reconfirm before proceeding ahead.
2011 Dec 21 5:58 PM
Check these FM's, One will give 4 decimals and other 9
BAPI_CURRENCY_CONV_TO_EXTERN_9 ( AMOUNT_EXTERNAL is declared with 23 and 4 decimals)
BAPI_CURRENCY_CONV_TO_EXTERNAL (AMOUNT_EXTERNAL is declared with 28 and 9 decimals)
May be you could copy any one of these and declare AMOUNT_EXTERNAL is declared with 5 decimals.
Hope this helps
2011 Dec 22 9:05 AM
@ JAY,
Yes, I agree with you that this is some kind of wierd requirement.
But when i checked something in SAP i was wondering why I was not getting the same in my object.
In VF03 when you open any Billing document the net amount for USD5 is displayed in 5 decimals, although when i do F1 on the net amount field I get the technical details as NETWR which is CURR 15 DEC 2, now my assumption is that there must be some routine which will overwrite the currency depending upon currency key maintained for USD5.
But in my object that is not present and hence after performing some calculations I am storing the same in a variable of type NETWR so it will covert whatever calculation is in 2 decimals. But for the customer i need to show that in 5 decimals. which should be same as displayed when i see the invoice using VF03.
Hence I want a perfect FM which will work for my case. means for larger values and smaller values it should behave as i described.
2011 Dec 22 4:54 PM
SAP actually hold the currency and some stuff in long decimal places to maintain accuracy all across... (if you worked in SD pricing its the same case) but finally moves to the field with decimal 2...
in other words.. sap calculated and derives values using decimal 3 or 5 but for display it uses 2 decimal values.... the same way you can local vairables of decimal 5 and do all you calculations and stuff but for display use 2 decimal place.
2011 Dec 22 4:58 PM
Have you tried this FM?
call function 'HRPBSNO_FORMAT_ZERO'
exporting
left = '3'
right = '5'
out_separator = '.'
changing
str = l_character_field.
First you have to assign your currency variable to this l_character_field.