03-27-2008 5:08 PM
Hi All,
We are using R/3 4.6C and for some reason, the command REPLACE ALL OCCURRENCES OF... is not recognised by the compiler. Is it because the this was introduced from the later versions?
If so can you please suggest an alternative to remove any special characters from a string.
Thanks!
03-27-2008 5:11 PM
Hi Sandeep,
Try this
in the below string # is replaced by space
REPORT YCHATEST .
DATA : V_STRING TYPE STRING.
V_STRING = 'avvvvvv#kjkjkjdfk#jkjklsf#'.
TRANSLATE V_STRING USING '# '.
CONDENSE V_STRING no-gaps.
WRITE : V_STRING.
03-27-2008 5:09 PM
hi , i think this is working...check it..
data:char(25) value '5#4#2#&1#&',
char1(9) .
replace all occurrences of '#' in char with 'and' .
replace all occurrences of '&' in char with 'num' .
write: char.
regards,
venkat.
03-27-2008 5:11 PM
You can use this...
DATA: text TYPE string.
text = 'Blag$is$an$ABAP$Consultant'.
WHILE sy-subrc EQ 0.
REPLACE '$' WITH space
INTO text.
ENDWHILE.
WRITE:/ text.
Greetings,
Blag.
03-27-2008 5:11 PM
Hi Sandeep,
Try this
in the below string # is replaced by space
REPORT YCHATEST .
DATA : V_STRING TYPE STRING.
V_STRING = 'avvvvvv#kjkjkjdfk#jkjklsf#'.
TRANSLATE V_STRING USING '# '.
CONDENSE V_STRING no-gaps.
WRITE : V_STRING.
03-27-2008 5:13 PM
Try and use the 'old' REPLACE statement. Look for exact syntax at help.
You might be right that this statement is not yet valid for you release, but the 'old' REPLACE will also do the trick, but in that case you will have to do it in a DO-ENDDO loop since you can't replace them all at once like the ALL OCCURENCES variant.
03-27-2008 5:26 PM
Hi All,
Thank yoy for your replies.
All occurences is still not working.
I am trying out the other solutions as well.
Can you also please let me know how I can replace ' (single quote)?
How do I specify this?
Thanks!
03-27-2008 5:28 PM
Like this...
DATA: TEXT TYPE STRING.
TEXT = 'Blag''is''an''ABAP''Consultant'.
while sy-subrc eq 0.
replace '''' with space
into text.
endwhile.
write:/ text.
Greetings,
Blag.
03-27-2008 5:29 PM
Maybe not the most efficient, but it seems to do what you want.
REPORT zz_temp.
DATA: g_v_string(80) TYPE c VALUE '123!@#abcDEF$%^456$%^xyz',
g_v_printable_chars(62) TYPE c,
g_v_alpha(52) TYPE c VALUE 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuzwxyz',
g_v_integers(10) TYPE c VALUE '0123456789',
g_v_len TYPE i.
CONCATENATE g_v_alpha g_v_integers INTO g_v_printable_chars.
g_v_len = STRLEN( g_v_string ).
WHILE sy-index LT g_v_len.
IF g_v_string+sy-index(1) CN g_v_printable_chars.
g_v_string+sy-index(1) = space.
ENDIF.
ENDWHILE.
CONDENSE g_v_string NO-GAPS.
WRITE 😕 g_v_string.
Edited by: Jerry Coleman on Mar 27, 2008 1:44 PM
03-27-2008 5:46 PM
Hi sandeep,
the solution which i can see is.. .. as follows..:
1) find out the length of string ex: v_length = strlen(v_str).
2) use do loop.....
do v_length times.
v_index = sy-indiex.
if v_str+v_index(1) CA (a-z or 0-9).
l_str+ctr(1) = v_str+v_index(1).
ctr = ctr + 1.
endif.
endloop.
3) in the above code i am trying to read the characters which is not special characters....
all the very best.....
regards,
sreenivasa sarma k.
03-27-2008 5:57 PM
Thank you all for ur replies. I am awarding points to most of you.