‎2009 Mar 18 12:16 PM
Hi,
I have a requirement in which i have to replace the character '|' with blank space. I have used the following command to replace.
Replace All occurrences of '|' in v_text1 with ' ' (Instead of Quotes i tried with SPACE option also) but it is not inserting blank space in between the characters.
Can anyone please help me out in this.
Thanks & Regards
Haritha.
‎2009 Mar 18 1:05 PM
Hi,
Please use the TRANSLATE statement.
DATA text TYPE string.
text = `ABC|def|GHR|hgashdfk`.
TRANSLATE text USING '| '.
Output: ABC def GHR hgashdfk.
So TRANSLATE, replaces all the '|' with SPACE.
Cheers,
Srini.
‎2009 Mar 18 12:20 PM
Hi,
Try below
REPLACE ALL OCCURRENCES OF '|' WITH ' '. " give space using (Altkey+255)
"using Alt key+255 it gives a single spaceRegards
Bala Krishna
‎2009 Mar 18 12:27 PM
Hi,
Thanks for the reply. Could you please put a sample code for that.
Thanks & Regards
Haritha.
‎2009 Mar 18 12:31 PM
Hi,
what balakrishna said will work perfectly fine
just try doing it like this
REPLACE ALL OCCURRENCES OF '|' IN w_string WITH ' '.instead of pressing space bar, hold the alt key and press 255. it will automatically give you the space, its the ASCII key value of space (ALT + 255).
that will definitely work.
regards
sarves
‎2009 Mar 18 12:32 PM
HI,
Use the above syntax, instead of typing space bar for space use (Alt key+255) means Alt key on key board holding that Alt key press numbers 255, the remove finger from Alt key it will give u a space.
Regards
Bala Krishna
‎2009 Mar 18 12:38 PM
Hi,
whats the data type of v_text1? try string. it works for me.
or try simply "Replace '|' into v_text1 with ' '." but it'l replace only once.
‎2009 Mar 18 12:43 PM
hi
try out this code it works for me
data : a type string VALUE 'ABC|def|GHR|hgashdfk'.
data : c type string .
data : b type c VALUE '|'.
replace ALL OCCURRENCES of '|' in a with ' '. " as bala krishan told press the key alt and type 255 .
write : a.regards
chinnaiya
‎2009 Mar 18 12:45 PM
Hi,
There is another option also to do the same but bit lenghty:
DATA:Len type i,
Counter type i,
String1(10) type c value 'Iadsfdiadsfdifd',
String2(10) type c.
Len = STRLEN ( String1 ).
Counter = 0.
while Countre LT Len.
if String1+Counter(1) EQ 'i'.
Concatenate String2 ' ' into String2.
else.
Concatenate String2 String1 into String2.
endif.
Write String2.Hope this might help you out.
Pooja
‎2009 Mar 18 12:48 PM
Hi Balakrishna,
I have tried the below code by using ALT+255, but it didnt gave me any space.
Data: v_text1 type string,
v_text2 type string.
v_text1 = 'ABC*DEF'.
move v_text1 to v_text2.
replace all occurrences of '*' in v_text2 with ''.
if sy-subrc = 0.
write:/ v_text1, v_text2.
endif.
Thanks & Regards
Haritha.
‎2009 Mar 18 12:53 PM
Hi Haritha,
ALT+255 will give a space, its ASCII format,
open a Notepad and write AB, place the cursor after A, and hold ALT key on keyboard, and press number 255 then remove finger from ALT key, you will see a space between A and B now.
Use same in the REPLACE statement to get space.
Regards
Bala Krishna
‎2009 Mar 18 12:59 PM
Actually, after pressing the number 255, u have to hold the alt for a while and then release your finger. Try in numeric pad of keyboard.
‎2009 Mar 18 1:02 PM
Hello Haritha,
I think the problem is the following: Character fields (data type c) cannot have blank spaces at the right side of the field. Thus, the character field ' ' which is used to replace the '|' character is actually ''.
If you use a string instead, the code should work:
DATA: gv_text1(20) TYPE c VALUE 'This|is|my|sample'.
* Replace | character with spaces
REPLACE ALL OCCURRENCES OF '|' IN gv_text1 WITH ` `.
WRITE gv_text1.
Regards
David
‎2009 Mar 18 1:05 PM
Hi,
Please use the TRANSLATE statement.
DATA text TYPE string.
text = `ABC|def|GHR|hgashdfk`.
TRANSLATE text USING '| '.
Output: ABC def GHR hgashdfk.
So TRANSLATE, replaces all the '|' with SPACE.
Cheers,
Srini.
‎2009 Mar 18 1:14 PM
Hi,
The below statement also works, however there is a twist.
REPLACE ALL OCCURRENCES OF '|' IN gv_text1 WITH ` `.
The space ` `, these characters are under the tilde sign on the keyboard, these are not the single quotes(see the difference, single quote ('), the other one is (`).
If you you ' ', the statement does not work.
so,
REPLACE ALL OCCURRENCES OF '|' IN gv_text1 WITH ' '. "Does not work:
Works:
REPLACE ALL OCCURRENCES OF '|' IN gv_text1 WITH ` `. " works
Hope you issue will be solved.
‎2009 Mar 18 1:14 PM
Hi Srinivas,
Thanks a lot. Your logic of Translate command worked.
Hi Balakrishna,
I think the logic which you said works only in versions which are greater than 4.7, it didn't worked for me even i tried to do it in notepad. Anywayz thanks a lot for the suggestions given.
Thanks & Regards
Haritha.