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

Curency conversion

Former Member
0 Likes
1,441

Hello Friends,

I need to convert a currency filed with 6 digits say 124.565127 to a Packed Decimal field, I am not able to get the desired output for instance if I have variablelike:

Data: V_VAR TYPE WRBTR VALUE u2018124.565127u2019.,

V_VAR1(4) TYPE P DECIMALS 6.

I am unable to move the V_VAR to V_VAR1 i.e. the V_VAR1 is getting rounded Like 124.57.Also I need the currency field to be converted to packed decimal filed with 6 decimal places and then I need to round off.

Please suggest.

Thanks

Meenakshi

6 REPLIES 6
Read only

Former Member
0 Likes
1,392

WRBTR is defined as having only 2 decimal places so your value is rounded up there and maintains that rounded value when you move it to a field with 6 decimal places.

Brent

Read only

Former Member
0 Likes
1,392

did you mean V_VAR1(4) TYPE P DECIMALS 6

try like:

V_VAR(15) type p decimals 6 value u2018124.565127u2019,

V_VAR1(15) type p decimals 6,

v_var1 = v_var will give you 124.565127.

if you define v_var1 as (15) type p decimals 2,

v_var1 = v_var should give you 124.57.

Edited by: DaveL on Aug 18, 2011 6:23 PM

Read only

0 Likes
1,392

Thanks for the reply, but i need a curency field to be moved to pakced field like the one below.Please suggest.

data: v_var1 type wrbtr value '14.235645'.

Thanks

Meenakshi.

Read only

0 Likes
1,392

Hi,

You have to know that currency amounts are always stored right-aligned in packed fields, whatever the number of real digits after the decimal point. For instance, 1000 JPY (Japanese Yen) is stored technically 10,00 in WRBTR !!! (WRBTR has technically 2 digits after the decimal point, while JPY has 0 decimals defined in table T005X). But when the amount is output, as it must always be related to a currency code field, SAP moves the decimal point to output "1000".

For more information, see : [SAP note 153707 (Currency translation miscalculates by 100, 1000..)|https://service.sap.com/sap/support/notes/153707], WRITE ... CURRENCY ...

But I'm not aware of any currency code with 6 digits after the decimal point. Does it really exist?, I thought the max was 3 or 4? even BAPIs are built for 4 maximum.

Sandra

Read only

0 Likes
1,392

Thanks Sandra, but we do have some currency fields(Values) where it is geetting displayed to 6 decimals for USD,like 14.2564417 and that needs to be rounded off to the nearest decimal place.

Thanks

Meenakshi

Read only

0 Likes
1,392

Meenakshi,

I can understand what you say, but your first post has misleaded everybody (of course the amount is rounded off to 2 decimals if you store your number in a 2 decimals field)

14.2564417 and that needs to be rounded off to the nearest decimal place

Could you update the following example and tell us what you want exactly?


DATA source TYPE p LENGTH 6 DECIMALS 7 value '14.2564417'.
DATA target TYPE p LENGTH 6 DECIMALS 6.
target = source. "half-up rounding to 6 decimals
WRITE target. "writes 14.256442

Sandra