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

function that converts an amount

Former Member
0 Likes
743

There is a function that converts an amount in accordance with WAERS input.

example

amount 100234

input waers with 2 decimal

output 1002,34

amount 1002,34

input waers with 3 decimal

output 100,234

Edited by: francesco aiello on Apr 29, 2010 1:10 PM

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
626

Hi francesco,

if anyway you catch the number of decimal places inot a number through string manipulation,

say you get the number of decimal places as n,

what you can do is,

divisor = '1'.
amount = '10094'.

do n times. " say 2
divisor = divisor * 10.  
enddo.
** now your divisor becomes 100!

now divide your amount--
amount = amount / divisor.  " now amount = 10094 / 100 = 100.94

Just a suggestion, you may have more efficient ways to do it.

Sumit

4 REPLIES 4
Read only

Former Member
0 Likes
627

Hi francesco,

if anyway you catch the number of decimal places inot a number through string manipulation,

say you get the number of decimal places as n,

what you can do is,

divisor = '1'.
amount = '10094'.

do n times. " say 2
divisor = divisor * 10.  
enddo.
** now your divisor becomes 100!

now divide your amount--
amount = amount / divisor.  " now amount = 10094 / 100 = 100.94

Just a suggestion, you may have more efficient ways to do it.

Sumit

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
626

You have to use the BAPI: BAPI_CURRENCY_GETDECIMALS to get how many decimals are defined for the currency

Edited by: Suhas Saha on Apr 29, 2010 4:53 PM:

If it is a report output or a form you have to use the Reference Currency field. It will automatically format your output based on the currency code. Else you have the BAPI_CURRENCY_CONV_TO_EXTERNAL to convert to external format.

Read only

Former Member
0 Likes
626

Hi,

There are two FM that can help you:

1. BAPI_CURRENCY_CONV_TO_EXTERNAL : This converts currency amounts from SAP internal data formats into external data formats.

2.BAPI_CURRENCY_CONV_TO_INTERNAL : This converts currency amounts from SAP external data formats into internal data formats.

Regards,

Sana.

Read only

Former Member
0 Likes
626

Hi

How about as follows.

WRITE int CURRENCY 'USD'.

USD has 2 decimal

Regards,

Gaito