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: 

Convert number format to XXX.XXX.XXX,XX

Former Member
0 Kudos

Hi,

I need to convert any number to format XXX.XXX.XXX,XX

For Eg. Number is 123456.00

expected 123.456,00

Please let me know any Function module used for this.

This is has to be moved to character field and then displayed so directly assigning to data element like KEBTR wont help.

Regards,

Shraddha

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Normally with displaying decimal values, the decimal display is taken from your user settings.

Perhaps change it over there so you get the desired output format?

17 REPLIES 17

former_member223537
Active Contributor
0 Kudos

Hi Shraddha,

WRITE 😕 lv_data  USING EDIT MASK 
                       ' ___.___.___,__'.


Move lv_data to l_field.

Thanks,

Best regards,

Prashant

0 Kudos

Hi Prashant,

I cannot use edit mask as we will not be sure of the length of the numer.

What I mean is this number is system calculated amount.

stored in system in format XXXXXX.XX

Eg 127689.50

16796.38

and I need to send this to SAVE_TEXT

So this will be converted into char

Now before passing it to SAVE_TEXT, I need to make it to correct format like 127,689.50

16.796,38

Hop this makes it clearer.

Former Member
0 Kudos

Hi,

I guess this might help you....

data:var1(10) tyep c default '123456.00,

var2(3) type c,

var3(15) type c.

split var1 at '.' into var1 var2.

concatenate var10(3) '.' var13(3) ',' var2 into var3.

write: var3.

Pooja

Former Member
0 Kudos

hI

There is no function module to convert corrency into XXX.

write logic using SPLIT function.

Regards

Sekhar

Former Member
0 Kudos

Check this code snippet.

DATA: num TYPE p DECIMALS 2.
CALL FUNCTION 'HRCM_STRING_TO_AMOUNT_CONVERT'
  EXPORTING
   string                    = '123456'
   decimal_separator         = ','
   thousands_separator       = '.'
 IMPORTING
   betrg                     = num .
IF sy-subrc <> 0.
ENDIF.
WRITE num left-justified.

Thanks

0 Kudos

Hi Nitesh,

I executed this FM HRCM_STRING_TO_AMOUNT_CONVERT by giving dummy data like 123456 , '.', ',' but it gave me same output whatever I pass. It does not convert the format. Can you please let me know how to execute it?

0 Kudos

Hi Shraddha,

You could use the following code:

DATA wa_curr TYPE dmbtr value '198765.88'.

DATA wa_curr2(16) TYPE c.

WRITE wa_curr TO wa_curr2.

wa_curr2 will have the amount properly formatted as per User preference... (198,765.88 or 198.765,88)

You could use wa_curr2 in SAVE_TEXT..

Revert if you need more.

Former Member
0 Kudos

Hi ,

U hav to use

WRITE <var> USING EDIT MASK 'RR___.___.___,__'.

Amitava

Former Member
0 Kudos

y number to format XXX.XXX.XXX,XX

For Eg. Number is 123456.00

expected 123.456,00

data: string1 type string,

string2 type string,

string3 type string.

string1 = 123,456.00.

find all accurences of string1 at ',' into v_line.

if v_line <= 2.

do v_line time.

split string1 at ', ' into string2 string3.

string2 = 123

string3 = 456.

exit.

enddo.

endif.

split string3 at '.' into string1.

now, replace the value with 'X'.

now string1 = .00

string2 = 123.

string3 = 456.

0 Kudos

Hi Chandra,

I do not mean I want literally number to be printed as XXXXXX

What I need is:

I will get variable numbers

16346.00

238765903.67

456.89

What I need is it should have ' .' as a separator in between.

16346.00 should be 16.346,00

238765903.67 should be 238.765.903,00

456.89 should be 456,00

These values were examples.

We could have any value here

Former Member
0 Kudos

Normally with displaying decimal values, the decimal display is taken from your user settings.

Perhaps change it over there so you get the desired output format?

0 Kudos

Hi Maen,

After changing this value needs to be passed to function module SAVE_TEXT where it would be taken care as a char field. Now char fields are not changed into the desired format.

That is the reason I need to change the format programmatically and then pass is to the FM.

0 Kudos

Hi Ankesh,

Can you please let me know what shall be the format of variable 2 in this case.

I need to do this. But I am not getting the correct format.

For you reference this is amount field and has to be converted into European format.

0 Kudos

Hi Shraddha ,

Please see the code below ,

data : num type DMBTR ,
       text type char15.

num = '16346.00'.
num = floor( num ).
write num CURRENCY 'USD'..

num = '238765903.67'.
num = floor( num ).
write num CURRENCY 'USD'..


num = '456.89'.
num = floor( num ).
write num to text CURRENCY 'USD'..
write text.

In case you want to write it directly , you can do it else move it to a varaibale as in case3 .

The only thing to check is that the output format will be based on the setting of the currency 'USD' in your system , in case it is not set properly then the display will not be correct.

Regards,

Arun

0 Kudos

HI Shraddha,

As in my code, the varibale wa_curr2 is TYPE c...

We have to keep it TYPE c to use the WRITE statement.

and also remember to keep the appropriate format in User preference also whosoever is going to execute the program.

0 Kudos

Thanks Arun

faisal_altaf2
Active Contributor
0 Kudos

Hi,

You can also check the following Sample Code i think it is working according to your requirements

DATA: amount TYPE p DECIMALS 2,
      camount(25).

amount = '2512.24'.
BREAK-POINT.

WRITE: amount TO camount.
CONDENSE: camount.
REPLACE ALL OCCURRENCES OF '.' IN camount WITH '-'.
REPLACE ALL OCCURRENCES OF ',' IN camount WITH '.'.
REPLACE ALL OCCURRENCES OF '-' IN camount WITH ','.
WRITE: camount.

Regards,

Faisal