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

Replace

Former Member
0 Likes
1,185

Hello ,

my requirement is if i have a string i want to chec if the 4th character from right is a dot or not.....if yes then replace it with comma.

if str = '123.546.236'

then it shud be 123.546,236.

also the contents of field are not of fixed length.ie. str = 12.365 or 12356.000.

Kindly provide the solution

regards

Pranali.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,157

Use this code:


data len type i.
compute len = strlen( str ).
len = len - 4.

if str+len(1) eq '.'.
 str+len(1) = ','.
endif.

Please mark points if the solution was useful.

Regards,

Manoj

9 REPLIES 9
Read only

seshatalpasai_madala
Product and Topic Expert
Product and Topic Expert
0 Likes
1,157

Hi,

use the Function module

STRING_REVERSE to reverse the string

and then use

REPLACE FIRST OCCURANCE OF '.' IN str WITH ','.

Again use

STRING_REVERSE

Regards,

Sesh

Read only

Former Member
0 Likes
1,158

Use this code:


data len type i.
compute len = strlen( str ).
len = len - 4.

if str+len(1) eq '.'.
 str+len(1) = ','.
endif.

Please mark points if the solution was useful.

Regards,

Manoj

Read only

Former Member
0 Likes
1,157

DATA : LV_CHAR TYPE C,

STR(10) TYPE C.

STR = 'Hel.oo'.

LV_CHAR = STR+3(1).

IF LV_CHAR EQ '.' .

STR+3(1) = ','.

ENDIF.

WRITE STR.

Thanks,

Mahesh

Read only

Former Member
0 Likes
1,157

Hey Pranali,

Try this out,

  • Get the lenght of your string str

len = strlen( str ).

  • Less 4, to get the right position

len = len - 4.

*Using offset get one caracter at that position, if it is a dot, change to comma

if str+len(1) = '.'.

str+len(1) = ','.

endif.

Hope this helps.

Regards,

Marcelo Moreira

Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
1,157
data: str(20) type c.
data: len type i.


str = '123.546.236'.

len = ( strlen( str ) - 4 ).

if str+len(1) = '.'.
  str+len(1) = ','.
endif.

write:/ str.

Regards,

Rich Heilman

Read only

kesavadas_thekkillath
Active Contributor
0 Likes
1,157

if str cs '.'.

REPLACE '.' WITH ',' INTO str.

endif.

reward if usefull.....

Read only

Former Member
0 Likes
1,157
REPORT ztest.

DATA : v_str TYPE string VALUE '123.546.236',
       v_char(250),
         v_len TYPE i.

v_char = v_str.
v_len = STRLEN( v_char ).

v_len = v_len - 4.

IF v_char+v_len(1) EQ '.'.
  v_char+v_len(1) = ','.
ENDIF.

v_str = v_char.

WRITE : v_str.
Read only

Former Member
0 Likes
1,157

v_len = stelen (str).

v_len = v_len - 3.

if str+0(v_len) = '.'.

replace str+0(v_len) with ','.

endif.

Read only

Former Member
0 Likes
1,157
If str+3(1) = '.'.         " If dot
   str+3(1) = ','.                 " replace with comma
endif.

reward if useful

Regards

Prax