Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Replacing space with '.'

Former Member
0 Likes
2,595

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.....

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
2,139
10 REPLIES 10
Read only

laurent_fournier2
Contributor
0 Likes
2,139

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.

Read only

Former Member
0 Likes
2,139

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

Read only

Former Member
0 Likes
2,139

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.

Read only

Former Member
0 Likes
2,139

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.

Read only

Former Member
0 Likes
2,140
Read only

Former Member
0 Likes
2,139

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.

Read only

Former Member
0 Likes
2,139

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

Read only

0 Likes
2,139

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.

Read only

MariaJooRocha
Contributor
0 Likes
2,139

Hi,

Try

Translate lv_uname using ' . '.

Regards,

Maria João Rocha

Read only

kesavadas_thekkillath
Active Contributor
0 Likes
2,139

just change ' ' to ` `.