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

Change separating char in numerical data

Former Member
0 Likes
1,711

Hi Everyone,

I have the problem of numerical data appearing with commas instead of points and vice versa, for example:

1.234.567,000 and I want it like --> 1,234,567.000

I cannot change the regional settings or defaults in SU3 as the format is correct in Spain, I just need to change it for the output of one program.

The program is collecting data from various tables, carrying out some calculations and creating a .txt file with the data in it, so changing the type to char or string is ok.

Regards,

Simon

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,660

Hello,

You can also try the code below.

It will get you the format that you want, irrecspective of the settings applied by the user.

  • For Getting the Decimal Settings of the User.

select single dcpfm into w_dcpfm

from usr01

where bname eq sy-uname.

write w_sf-erg1amt currency c_usd to w_ear_amt1.

  • Convert Currency to Desired format.

if not w_ear_amt1 is initial.

if w_dcpfm eq c_x.

elseif w_dcpfm is initial.

split w_ear_amt1

at c_comma

into w_earamt1_1

w_earamt1_2.

translate w_earamt1_1 using c_chng.

clear w_ear_amt1.

concatenate w_earamt1_1 w_earamt1_2 into w_ear_amt1

separated by c_dot.

endif.

endif.

Hope it helps.

Thanks,

Jayant

14 REPLIES 14
Read only

Former Member
0 Likes
1,660

Hello,

If you are always getting the values as 1.234.567,000 for all the users then you can use.

replace all occurences of '.' in <your variable' with ','.

Thanks,

Jayant

Read only

0 Likes
1,660

Hi Jayant,

I already tried that and it doesn't work. It just took away the ',' but didn't replace it. It surprised me, I was sure it would work.

Thanks anyway,

Simon

Read only

0 Likes
1,660

use translate

shift v_char left deleting leading spaces.

translate v_char using ', '.

condense v_char no-gaps.

Read only

0 Likes
1,660

>

> use translate

>

> shift v_char left deleting leading spaces.

> translate v_char using ', '.

> condense v_char no-gaps.

use translate as

translate v_char using '.,,.'.

Edited by: kartik tarla on Dec 5, 2008 5:13 PM

Read only

Former Member
0 Likes
1,661

Hello,

You can also try the code below.

It will get you the format that you want, irrecspective of the settings applied by the user.

  • For Getting the Decimal Settings of the User.

select single dcpfm into w_dcpfm

from usr01

where bname eq sy-uname.

write w_sf-erg1amt currency c_usd to w_ear_amt1.

  • Convert Currency to Desired format.

if not w_ear_amt1 is initial.

if w_dcpfm eq c_x.

elseif w_dcpfm is initial.

split w_ear_amt1

at c_comma

into w_earamt1_1

w_earamt1_2.

translate w_earamt1_1 using c_chng.

clear w_ear_amt1.

concatenate w_earamt1_1 w_earamt1_2 into w_ear_amt1

separated by c_dot.

endif.

endif.

Hope it helps.

Thanks,

Jayant

Read only

0 Likes
1,660

Jayant,

Could you make your code a bit clearer and indicate the type of your variables?

None of the other suggestions have fixed the problem.

Thanks,

Simon

Read only

0 Likes
1,660

Use FM

CLSE_SELECT_USR01 to get DECIMAL_SIGN and SEPARATOR.

check if SEPARATOR = ',' and DECIMAL_SIGN = '.' ==> No change required.

else.

Use FM BAPI_CURRENCY_CONV_TO_EXTERNAL to convert your numeric value to external (display) format.

Write OUTPUT of above FM to temp_variable (temp_variable(30) type c).

Now use replace , to . and . to ,

Regards,

Mohaiyuddin

Read only

0 Likes
1,660

Hi Mohaiyuddin,

I'm not sure what exactly the FM does but it worked, I had to change it to 3 dec places afterwards but it at least it works.

Why didn't the REPLACE work with the initial value I had?

Thanks,

Simon

Read only

0 Likes
1,660

Because internally values were still numeric.

SAP converts this value to EXTERNAL while displaying (using WRITE) or sending it other outputs (ALV etc).

Second FM explicitly converts numeric value to external format (again external format is specific to currency key, some may have 2 decimals, some may have 3 etc...). After that writing to another variable (with character format) will actually have , and . in your variable. Replacing them will work at that point.

Regards,

Mohaiyuddin.

Read only

0 Likes
1,660

Thanks to everyone for the suggestions.

Special thanks to Mohaiyuddin, your solution was the best.

Regards,

Simon

Read only

Former Member
0 Likes
1,660

translate wa_num1 USING ',..,'.

This will translate , to . and . to ,

This should resolve your problem

Read only

Former Member
0 Likes
1,660

Hi

For comma problem,

it comes from user settings

SYSTEM--->USER PROFILE --> OWN DATA

(Goto DEFAULTS tab)

there we can maintain the number format / decimal notation

Regards,

Rohit

Read only

0 Likes
1,660

Hi Rohit,

That would work for me but what happens when someone else uses it?

Also, as I explained in my question it's just for this one program, I don't have to change my user settings as the comma is correct in Spain (where I'm working). I've seen it done before but I just can't remember how it was done, I think there was a function involved.

Regards,

Simon

Read only

Former Member
0 Likes
1,660

Hi,

U can take this help.

data: v_char(13) type c value '1.234.567,000'.

shift v_char left deleting leading space.

replace all occurrences of ',' in v_char with '+'.

translate v_char using '.,'.

replace all occurrences of '+' in v_char with '.'.

condense v_char no-gaps.

write:/ v_char.

Regards

Srimanta