Application Development 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: 

Currency format

Former Member
0 Kudos

Hi!

I have a character field, which contains numbers like this: 123456.78

I would like to convert them into an another character field (NOT currency) iwth a format like this: 123.456,78

Of course it has to handle the lower and higher numbers also:

123.45 -> 123,45

111222333,44 -> 111.222.333,44

What's the easiest solution for this?

Thank you

Tamá

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi Tamas

Please use the Write statement with the currency addition.

Something like,

write v_amt_char1 to v_amt_char2 currency 'USD'.

Youor currency key will vary based upon the entry in T005X with the format that you are looking for.

Hope this helps !

Regards

Ranganath

4 REPLIES 4

Former Member
0 Kudos

Hi Tamas, check this code.

Currency Conversion:

______________________

Use the function module

CONVERT_TO_LOCAL_CURRENCY

Writing currency amount to string without thousands seperator

This is usefull e.g. i connection with batch input/call transaction.

  • GI_OUTPUT-WRBTR: Field type Currency with amount

  • L_AMOUNT_STRING: Field type c with amount

PERFORM AMOUNT_TO_STRING USING GI_OUTPUT-WRBTR

CHANGING L_AMOUNT_STRING.

FORM AMOUNT_TO_STRING USING P_AMOUNT

CHANGING P_AMOUNT_STRING.

DATA L_SEP(1) TYPE C.

PERFORM GET_THOUSAND_SEPERATOR USING L_SEP.

WRITE P_AMOUNT TO P_AMOUNT_STRING.

REPLACE L_SEP WITH ' ' INTO P_AMOUNT_STRING.

CONDENSE P_AMOUNT_STRING NO-GAPS.

WRITE P_AMOUNT_STRING TO P_AMOUNT_STRING RIGHT-JUSTIFIED.

ENDFORM.

FORM GET_THOUSAND_SEPERATOR USING P_SEP.

DATA: L_AMOUNT LIKE BSEG-DMBTR,

L_AMOUNT_STRING(15) TYPE C.

  • Find 1000 seperator. If decimal seperator = . then

  • 1000 seperator = , else 1000 seperator = .

L_AMOUNT = '1.00'.

WRITE L_AMOUNT TO L_AMOUNT_STRING.

IF L_AMOUNT_STRING CS ','.

P_SEP = '.'.

ELSE.

P_SEP = ','.

ENDIF.

ENDFORM.

Convert amount to/from string

CALL FUNCTION 'HRCM_AMOUNT_TO_STRING_CONVERT'

EXPORTING

betrg = 3000

WAERS = 'DKK'

  • NEW_DECIMAL_SEPARATOR =

  • NEW_THOUSANDS_SEPARATOR =

IMPORTING

STRING = slam

.

CALL FUNCTION 'HRCM_STRING_TO_AMOUNT_CONVERT'

EXPORTING

string = slam2

DECIMAL_SEPARATOR = '.'

  • THOUSANDS_SEPARATOR =

WAERS = 'HUF'

IMPORTING

BETRG = b2

  • EXCEPTIONS

  • CONVERT_ERROR = 1

  • OTHERS = 2

Language depending formatting

To format a currency amount with decimals according to the currency use

WRITE and the CURRENCY option.

Currency keys an d numbers of decimals are defined in table TCURX Decimal

Places in Currencies.

E.G.

Formatting an amount in Kuwatian Dinars:

Dmbtr = 123456.

Write dmbtr currency 'KUD'

123.456

Write dmbtr currency 'USD'

1234.56

Note that the formatting does not depend on the number of decimals in the

number in the program.

Dmbtr = '12.3456'.

Write dmbtr currency 'USD'

1234.56

To format the decimal and thousand sepearators according to the settings for

a specific country,

use the statement SET COUNTRY <country key>

Settings for countries are defined in table T005 Countries.

The country key used in the statement is field LAND1

E.g.

set country 'US'

kindly reward if found helpful.

cheers,

Hema.

Former Member
0 Kudos

Hi,

Go in su01 give the user for which you want to define these settings and under user settings you can define the number formats.

Hope it helps.

Regards,

Siddhesh S.Tawate

Former Member
0 Kudos

Hi Tamas

Please use the Write statement with the currency addition.

Something like,

write v_amt_char1 to v_amt_char2 currency 'USD'.

Youor currency key will vary based upon the entry in T005X with the format that you are looking for.

Hope this helps !

Regards

Ranganath

0 Kudos

Unfortunaltey direct WRITE was not working. But I've got some cool ideas from the FM HRCM_STRING_TO_AMOUNT_CONVERT.

The working solution is the following:

DATA: gv_amount_char1(20),

gv_amount_char2(20),

gv_packed TYPE p DECIMALS 2.

MOVE '123456.78' TO gv_amount_char1.

CLEAR: gv_amount_char2, gv_packed.

MOVE gv_amount_char1 TO gv_packed.

WRITE gv_packed TO gv_amount_char2.

  • output of gv_amount_char2 is 123.456,78