‎2008 Jun 30 11:27 AM
Hye Gurus,
i have a variable of type char40.
when i am using
replace all occurences of space in var with '_'.
it is throwing an exception.
Please suggest, my requirement is i have to replace spaces with underscore '_'.
Thanks in advance,
Imran.
‎2008 Jun 30 11:30 AM
hi,
you can do with TRANSLATE:
TRANSLATE string USING ' _'.
(pls note there is a space before the undescore)
hope this helps
ec
‎2008 Jun 30 11:30 AM
hi,
you can do with TRANSLATE:
TRANSLATE string USING ' _'.
(pls note there is a space before the undescore)
hope this helps
ec
‎2008 Jun 30 11:31 AM
‎2008 Jun 30 11:33 AM
Hi Imran,
Try these examples. :
Addition 1
... FIRST OCCURRENCE OF
Effect
In the string text, replaces the first occurrence of the search text old with new. This addition is also the default setting.
Example
DATA: myText type string.
myText = 'abcabcabcabcabc'.
REPLACE FIRST OCCURRENCE OF 'abc' IN myText WITH 'XYZ'.
returns: myText = 'XYZabcabcabcabc', sy-subrc = 0
Addition 2
... ALL OCCURRENCES OF
Effect
In the string text, replaces all patterns found that do not overlap. Bear in mind that the system searches the entire string and then replaces old with new.
Example 1
DATA: c4(4) TYPE C.
c4 = 'abab'.
REPLACE ALL OCCURRENCES OF 'ab' IN c4 WITH 'CCC'.
returns: c4 = 'CCCC', sy-subrc = 2
not c4 = 'CCCa', sy-subrc = 2. (as it would, if the system replaced each search string successively).
Example 2
DATA: myText type string.
myText = 'abcabcabcabcabc'.
REPLACE ALL OCCURRENCES OF 'abc' IN myText WITH 'XYZ'.
returns: myText = 'XYZXYZXYZXYZXYZ', sy-subrc = 0
Regards,
Swapna
‎2008 Jun 30 11:34 AM
You can write:
data:
zlv_char type char40.
translate zlv_char using ' _'.
Sorry, I see that Eric already gave the correct answer.
Regards,
John.
Edited by: John Heutmekers on Jun 30, 2008 12:35 PM
‎2008 Jun 30 11:35 AM
Hi,
Try using translate
TRANSLATE <variablename> USING ' _' .
Regards,
Sai
‎2008 Jun 30 11:36 AM
hi Imran,
Try translate Instead of Replace.
Regards,
Sachin M M
‎2008 Jun 30 11:38 AM
Hi,
use this.. REPLACE ALL OCCURRENCES OF ' ' IN wa_final-last_name WITH '_'.
‎2008 Jun 30 11:44 AM
try:
data str(50) VALUE 'abc def ghi'.
data: in type i, ind TYPE i.
in = STRLEN( str ).
WHILE ind lt in.
if str+ind(1) = ''.
move '_' to str+ind(1).
endif.
ind = ind + 1.
ENDWHILE.
WRITE / str.
plz reward points if dis helps
‎2008 Jun 30 11:52 AM
‎2008 Jun 30 12:00 PM
Hi imran ,
Try this once,
data:
w_char1(40) type c,
w_c type c value space,
w_char(40) type c ,
w_c1 type c value '_',
w_new type c.
w_char = ' hello hai how r u'.
condense w_char.
while w_char ne ' '.
w_new = w_char(1).
shift w_char left.
if w_new eq space.
replace w_new in w_char with w_c1.
endif.
concatenate w_char1 w_new into w_char1.
endwhile.
write w_char1.
Regards,
Rajitha.