2012 Jul 05 12:47 PM
Hi experts,
I have a requirement in which I need to replace all the spaces in a string with '.'. When I write the below code it is throwing dumb ..
REPLACE all occurrences of ' ' IN LV_UNAME WITH '.' .
The error I am getting is
An exception occurred that is explained in detail below.
The exception, which is assigned to class 'CX_SY_REPLACE_INFINITE_LOOP', was
not caught and
therefore caused a runtime error.
The reason for the exception is:
In the running program "ZSREE_TEST32", the command "REPLACE ALL OCCURENCES
OF "' '" ... " was to be executed. However, field "' '" has the length 0,
which would have resulted in an endless loop. Therefore, the program
was terminated.
Please help.....
2012 Jul 05 2:07 PM
2012 Jul 05 12:57 PM
As the dump says, you tried to replace the '' in an empty field.
try this.
If not lv_uname is initial.
replace all occ.......
endif.
regards.
2012 Jul 05 1:05 PM
Hi,
It is always good to use the syntax FIND before REPLACE.
FIND FIRST OCCURRENCE OF " " IN lv_uname.
If Sy-subrc = 0.
REPLACE ALL OCC...
endif.
if sy-subrc = 0, it means we have atleast one search string the field.
if sy-subrc NE 0, it means we dont have search sting in the field.
Cheers
~Niranjan
2012 Jul 05 1:28 PM
hi try to use this,
find space in LV_UNAME.
if sy-subrc eq 0.
REPLACE all occurrences of space IN LV_UNAME WITH '.' .
endif.
2012 Jul 05 1:47 PM
Try this.
do (n) times.
replace ' ' with '.' into (your string)
enddo.
n would be total words used in your string or if you sure string may not contain words more then 100 or 1000 or whatever then you can use fix number of loop ..i.e n = 10 or n = 100 or n = 1000.
2012 Jul 05 2:07 PM
2012 Jul 05 2:12 PM
EDIT: IGNORE THIS POST. Krupa posted the correct answer.
Is lv_uname actually a string, or is it something with a set length like sy-uname? If its something with a fixed length, try this:
DATA: lv_uname TYPE syuname,
lv_length TYPE i.
lv_uname = 'John Doe'.
lv_length = strlen( lv_uname ).
DO lv_length TIMES.
IF lv_uname+sy-index(1) IS INITIAL.
lv_uname+sy-index(1) = '.'.
ENDIF.
ENDDO.
For some reason though, this code is adding an extra '.' at the very end of lv_uname. You can always remove that one character though:
lv_uname+lv_length(1) = space.
2012 Jul 05 5:55 PM
thank you guys,
i checked then link in krupa's post.it solved my my problem...
but i found another way to do it....
translate lv_uname using ' .' .
here we have to give a space before the dot in the single qotes..
regards ,
Noufal Rahman
2012 Jul 09 2:50 PM
Isn't that what the second link in Krupa's post told you to do? That's not another way, its the way that was recommending.
2012 Jul 09 5:13 PM
Hi,
Try
Translate lv_uname using ' . '.
Regards,
Maria João Rocha
2012 Jul 10 5:49 AM