‎2008 Nov 05 9:45 AM
Hello All,
I would like to replace space in a string to an underscore.
Eg : 'LN MAT' should be changed to LN_MAT.
I tried this code
data : ls_text type mara-matnr.
REPLACE ALLOCCURRENCES OF SPACES
of ls_text with '_".
Runtime exception REPLACE_INFINITE_LOOP is thrown. Could anyone please help
me out as to what is the solution.
Thanks
Sudha
‎2014 Nov 10 3:41 PM
REPLACE ALL OCCURRENCES OF ` ` IN ls_text WITH '_'.
Please use Grave Accent ( ` ) instead of Apostrophe ( ' ), otherwise the expression ' ' will be handled like empty.
The expression ` ` will be handled as string.
‎2008 Nov 05 9:50 AM
Hello,
Give me one example with the value from the table which you want to place _ in space.
‎2008 Nov 05 9:52 AM
I want to change the string 'LN MAT' in to LN_MAT.
The string 'LN MAT' contain a space in between.
‎2008 Nov 05 9:53 AM
Hi,
U can use replace first occurance of ' ' with '_' instead of replace all occurances.
Regards,
Anju
‎2008 Nov 05 9:56 AM
Hello,
Try this.
DATA: y_v_text TYPE char10.
MOVE: 'LN MAT' TO y_v_text.
REPLACE ' ' WITH '_' INTO y_v_text.
WRITE:/ y_v_text.
‎2008 Nov 05 9:56 AM
Hi,
check the code:
DATA:
BEGIN OF wa,
data(255),
END OF wa.
DATA:
itab LIKE STANDARD TABLE OF wa WITH HEADER LINE.
DATA:
v_string1 TYPE string VALUE 'LV MAT',
v_string2 type string.
SPLIT v_string1 AT space INTO TABLE itab.
loop at itab.
concatenate v_string2 itab-data into v_string2 separated by '_'.
endloop.
shift v_string2 left deleting leading '_'.
write: / v_string2.Thanks & Regards,
Navneeth K.
‎2008 Nov 05 9:58 AM
just use TRANSLATE:
TRANSLATE string USING ' _'. "pls. note there is a space before the undersore
‎2008 Nov 05 9:58 AM
Hi,
replace all occurrences of space
in <field> with '_' .
Thanks,
Krishna
‎2008 Nov 05 9:59 AM
use this TRANSLATE abc USING ' _'.
note that inside the quotes we have space followed by _ which means replace space by _.
try sap help for translate for more info.
‎2008 Nov 05 9:59 AM
Use IN in PLace of OF
REPLACE ALLOCCURRENCES OF SPACES IN ls_text with '_".
It will Work
Thanks
Saurabh
‎2008 Nov 05 9:59 AM
Hello,
Please check if the material number is empty. Because the error that you are getting is one of the exceptions of the REPLACE...
Catchable Exceptions
CX_SY_REPLACE_INFINITE_LOOP
Cause: Substring of length 0 generates an endless loop when searching for all occurrences.
Runtime Error: REPLACE_INFINITE_LOOP (catchable)
Try to catch all the errors and find out the cause for it.
Thanks,
Jayant
‎2008 Nov 05 10:30 AM
Hi Sudha
Tried at my end. The following code works :-
while sy-subrc eq 0.
replace space with '_' into ls_text .
endwhile.
Cheers !!
Neeraj
‎2013 Sep 13 4:05 PM
A little late, but I just ran into this problem for the first time. Another option I would suggest is:
REPLACE [ALL OCCURENCES OF] REGEX '\s' IN ls_text WITH '_'.
‎2014 Nov 10 3:41 PM
REPLACE ALL OCCURRENCES OF ` ` IN ls_text WITH '_'.
Please use Grave Accent ( ` ) instead of Apostrophe ( ' ), otherwise the expression ' ' will be handled like empty.
The expression ` ` will be handled as string.