‎2007 May 11 7:31 PM
Hi ,
I am trying to replace a character of the field from the itab.
itab-f1 = 'HOPT & SCHULER GMBH & CO KG'.
My code is like this:
loop at itab.
tmp = itab-f1.
IF lf_tmp CS '&'.
REPLACE '&' WITH '&' INTO lf_tmp.
ENDIF.
itab-f1 = tmp.
endloop.
I am able to change only the first '&' by doing this.
<b>HOPT & SCHULER GMBH & CO K</b>
How can I do both the '&'?
anyone help me out ASAP
‎2007 May 11 9:28 PM
Hi,
Okay..You can use the Function module WRB_UTIL_STRING_REPLACE
Try this code
DATA: v_string TYPE string.
v_string = 'HOPT & SCHULER GMBH & CO KG'.
CALL FUNCTION 'WRB_UTIL_STRING_REPLACE'
EXPORTING
pi_search_string = '&'
pi_replace_string = '''&'''
CHANGING
pc_string = v_string
EXCEPTIONS
search_string_too_long = 1
missing_search_string = 2
OTHERS = 3.
IF sy-subrc = 0.
WRITE: / v_string.
ENDIF.
Thanks,
Naren
‎2007 May 11 7:32 PM
‎2007 May 11 7:34 PM
Hi ramana,
Do you have the
REPLACE all occurances of '&' in v_str into v_target.
Regards
Ravi
‎2007 May 11 8:05 PM
I get error ...<b>unable to interpret occurances</b>
And can you give me the syntax..for translate in my case
‎2007 May 11 8:23 PM
it was a spelling mistake..
its occurences and not occurances.
Regards,
Ravi
‎2007 May 11 9:14 PM
I tried all these spellings in 4.6c
OCCURRENCES
OCCURENCES
OCCURANCES
all show an error
‎2007 May 11 9:19 PM
that option for REPLACE probably doesn't exist in 46c.. I use it on my 47..
~Suresh
‎2007 May 11 8:08 PM
Hi,
Let's say you want to replace '&' with '1'.
loop at itab.
tmp = itab-f1.
TRANSLATE tmp using '&1'.
itab-f1 = tmp.
endloop.
Regards,
Ferry Lianto
‎2007 May 11 9:20 PM
TRANSLATE tmp using '&1'.
this also didnot work for me.
I guess this is because ...I have given it like this..
translate lf_tmp using '&&'.
I am translating & with '&'
Message was edited by:
ramana peddu
‎2007 May 11 8:21 PM
Hi Ramana,
Try using the following code.
LOOP AT itab.
REPLACE ALL OCCURRENCES OF '&' IN itab-f1 WITH '<text string>'.
MODIFY itab TRANSPORTING f1.
ENDLOOP.
where <text string> = String that should replace &
Let me know if this helps.
‎2007 May 11 9:17 PM
Hi,
replace all occurences addition is not available in 4.6c..
You have to use TRANSLATE as mentioned by Ferry.
Thanks,
Naren
‎2007 May 11 9:22 PM
Hi,
It is working...
Check this sample code with your string..
DATA: v_string TYPE string.
v_string = 'HOPT & SCHULER GMBH & CO KG'.
TRANSLATE v_string USING '&1'.
Thanks,
Naren
WRITE: / v_string.
‎2007 May 11 9:23 PM
Hi,
Do you want to replace & with '&'
Before replacing
HOPT & SCHULER GMBH & CO KG
After replacing
HOPT '&' SCHULER GMBH '&' CO KG
Do you want this..
Thanks,
Naren
‎2007 May 11 9:28 PM
Hi,
Okay..You can use the Function module WRB_UTIL_STRING_REPLACE
Try this code
DATA: v_string TYPE string.
v_string = 'HOPT & SCHULER GMBH & CO KG'.
CALL FUNCTION 'WRB_UTIL_STRING_REPLACE'
EXPORTING
pi_search_string = '&'
pi_replace_string = '''&'''
CHANGING
pc_string = v_string
EXCEPTIONS
search_string_too_long = 1
missing_search_string = 2
OTHERS = 3.
IF sy-subrc = 0.
WRITE: / v_string.
ENDIF.
Thanks,
Naren
‎2007 May 11 9:47 PM
I did it like this ...
CALL FUNCTION 'WRB_UTIL_STRING_REPLACE'
EXPORTING
pi_search_string = '&'
pi_replace_string = 'amp;'
changing
pc_string = lf_tmp
EXCEPTIONS
SEARCH_STRING_TOO_LONG = 1
MISSING_SEARCH_STRING = 2
OTHERS = 3
.
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
It went into a dump.
<b>Thank you Naren I got it</b>
Message was edited by:
ramana peddu
‎2007 May 11 9:52 PM
Hi,
The data type should be string..For all the parameters..ALso you should give '''&''' in the replace string parameter...Instead of '&'
Try this..
DATA: V_STRING TYPE STRING.
V_STRING = IF_TMP.
CALL FUNCTION 'WRB_UTIL_STRING_REPLACE'
EXPORTING
pi_search_string = '&'
pi_replace_string = '''&'''
changing
pc_string = v_string
EXCEPTIONS
SEARCH_STRING_TOO_LONG = 1
MISSING_SEARCH_STRING = 2
OTHERS = 3.
if_tmp = string.
Thanks,
Naren
‎2007 May 11 10:06 PM
Hi,
Please make sure to reward points for helpful answers...
Thanks,
Naren
‎2007 May 14 12:19 PM
Sorry Naren , I forgot to reward points ...see I have done it
‎2007 May 12 3:51 PM
Hi,
Please try this.
data: v_str1(1) type c value '&',
v_str2(3) type c value '''&''',
v_len type i.
loop at itab.
lf_tmp = itab-f1.
if lf_tmp cs v_str1.
v_len = strlen( lf_tmp ).
do v_len times.
replace v_str1 with v_str2 into lf_tmp.
enddo
endif.
itab-f1 = lf_tmp.
modify itab.
endloop.
Regards,
Ferry Lianto