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

REPLACE ALL OCCURRENCES

Former Member
0 Likes
1,033

HI All,

How can I replace ' - ' with SPACE.

I m using

REPLACE ALL OCCURRENCES OF '-' IN VALUE WITH ' '.

It is removing '-' but not getting space.

How can I have space.

Thanks,

Anshul.

7 REPLIES 7
Read only

andrea_galluccio2
Contributor
0 Likes
974

Hi ,

use TRANSLATE <field> using '- '.

Bye

Andrea

Read only

Former Member
0 Likes
974

Try this code

Suppose var_a is haveing data which have data along with '-' and has to be replaced by space

data: temp(1) type c value '-'.

REPLACE temp WITH space INTO var_a.

Now see the content of variable var_a all the '-' will be replaced by space.

Hope this helps.

Regards

Bikas

Read only

Former Member
0 Likes
974

HI

Use:

TRANSLATE wa_var USING '- '.

This should work for u.

Read only

Former Member
0 Likes
974

Hi,

The below code will work for your requirement.

DATA:w_txt TYPE char50 VALUE 'Hi How-are-you?'.
 
DO."Repeat until ',' is thr
  IF w_txt CA '-'. "Checking for '-'.
    w_txt+sy-fdpos(1) = space. "Replacing the '-' with space
  ELSE.
    EXIT. "Come out when thr is no '-'.
  ENDIF.
ENDDO.
 
WRITE:/ w_txt.

i/p is: Hi How-are-you?

o/p is : Hi How are you?

Hope thi helps you.

Regards,

Manoj Kumar P

Edited by: Manoj Kumar on Jan 9, 2009 12:23 PM

Read only

Former Member
0 Likes
974

data:val(10) value 'hh-m-kk'.

TRANSLATE val USING '- '.

write val.

Read only

Former Member
0 Likes
974

Hi,

In this case you would have to replace it by applying the logic.

first find '-' and then replace it with ' '.

use this code,this is working surely:

DATA: g_string TYPE string VALUE 'abc-def-ghi-jkl-',
g_newstring TYPE string,
g_text(1) TYPE c VALUE '-',
g_cnt TYPE i,
g_char(1) TYPE c,
g_int TYPE sy-index,
g_flag(1) TYPE c.


g_cnt = STRLEN( g_string ).
DO g_cnt TIMES.
  IF g_char IS INITIAL.
    g_char = g_string+0(1).
  ELSE.
    g_int = sy-index - 1.
    g_char = g_string+g_int(1).
  ENDIF.
  IF g_char = '-'.
    g_flag = 'X'.
    CONCATENATE ' ' g_newstring INTO g_newstring.
  ELSE.
    IF g_flag = 'X'.
      CONCATENATE g_newstring g_char INTO g_newstring separated by space.
      clear g_flag.
    ELSE.
      CONCATENATE g_newstring g_char INTO g_newstring.

    ENDIF.
  ENDIF.

ENDDO.

Regards,

Neha

Edited by: Neha Shukla on Jan 9, 2009 5:28 PM

Read only

Former Member
0 Likes
974

hi,

try this

data: var(20) type c.

data: begin of itab occurs 0 ,

var(20) type c,

end of itab.

var = 'HAO-how-are-you'.

write:/ var.

split var at '-' into TABLE itab.

CLEAR VAR.

LOOP AT ITAB.

IF SY-TABIX EQ 1.

CONCATENATE ITAB-VAR VAR INTO VAR SEPARATED BY SPACE.

ELSE.

CONCATENATE VAR ITAB-VAR INTO VAR SEPARATED BY SPACE.

ENDIF.

ENDLOOP.

WRITE:/ VAR.

regards,

Venkatesh