‎2008 Dec 05 10:53 AM
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
‎2008 Dec 05 11:04 AM
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
‎2008 Dec 05 10:59 AM
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
‎2008 Dec 05 11:03 AM
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
‎2008 Dec 05 11:03 AM
use translate
shift v_char left deleting leading spaces.
translate v_char using ', '.
condense v_char no-gaps.
‎2008 Dec 05 11:40 AM
>
> 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
‎2008 Dec 05 11:04 AM
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
‎2008 Dec 05 11:26 AM
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
‎2008 Dec 05 11:34 AM
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
‎2008 Dec 05 12:05 PM
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
‎2008 Dec 05 12:12 PM
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.
‎2008 Dec 05 12:35 PM
Thanks to everyone for the suggestions.
Special thanks to Mohaiyuddin, your solution was the best.
Regards,
Simon
‎2008 Dec 05 11:18 AM
translate wa_num1 USING ',..,'.
This will translate , to . and . to ,
This should resolve your problem
‎2008 Dec 05 11:27 AM
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
‎2008 Dec 05 11:38 AM
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
‎2008 Dec 05 12:06 PM
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