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 with space

Former Member
0 Likes
1,016

Hi

I have an requirement where i have to replace one character with space. Suppose in 'SAPISGREAT' word ' I ' shoud get replace with space liek SAP SGREAT. The word might change dynamically.So whenever ' I ' comes in the word I sould replace with space. When I use REPLACE commnand for the smae the word is truncating like SAPSGREAT. 'I' is not coming but no space.Any help greatly appricated.

Rgards

Raj.

9 REPLIES 9
Read only

Former Member
0 Likes
910

Try as follows:

FORM ZSTRING_CONV.

DATA: STR_LEN LIKE SY-FDPOS,

RSTR_LEN LIKE SY-FDPOS,

OFF LIKE SY-FDPOS.

DATA: IDX LIKE SY-FDPOS, "mn B20K054003

CL LIKE SY-FDPOS. "mn B20K054003

DATA: RSTRING(40).

DATA: STRING(40). " value 'A,N,I,L'.

  • data: n_char(1).

FIELD-SYMBOLS: <NLS_CHAR>. "mn B20K054003

  • field-symbols: <string>, <rstring>.

MOVE ttab-rec TO STRING.

MOVE SPACE TO RSTRING.

STR_LEN = STRLEN( STRING ).

DESCRIBE FIELD RSTRING LENGTH RSTR_LEN.

IF RSTR_LEN < STR_LEN. RAISE TOO_SMALL. ENDIF.

WHILE IDX < STR_LEN. "mn B20K054003

ASSIGN STRING+IDX(*) TO <NLS_CHAR>. "mn B20K054003

IF SY-LANGU EQ '2'. "mn B20K054003

CALL FUNCTION 'NLS_THAI_CHARLEN' "mn B20K054003

EXPORTING "mn B20K054003

THAI_STRING = <NLS_CHAR> "mn B20K054003

CHANGING "mn B20K054003

THAI_CHARLEN = CL. "mn B20K054003

ELSE. "mn B20K054003

CL = CHARLEN( <NLS_CHAR> ). "mn B20K054003

ENDIF. "mn B20K054003

IF IDX NE 0. "mn B20K054003

SHIFT RSTRING RIGHT BY CL PLACES."mn B20K054003

ENDIF. "mn B20K054003

IF STRING+IDX(CL) CA 'I'.

STRING+IDX(CL) = ''.

ENDIF.

RSTRING0(CL) = STRINGIDX(CL). "mn B20K054003

IDX = IDX + CL. "mn B20K054003

ENDWHILE. "mn B20K054003

ENDFORM.

Read only

sridhar_meesala
Active Contributor
0 Likes
910

Hi,

Try this,

DATA: T(10) VALUE 'SAPISGREAT',
STRING LIKE T,
STR1(1) VALUE 'I',
STR2(1) VALUE ' '.

STRING = T.

REPLACE STR1 WITH STR2 INTO STRING.
WRITE / STRING.

Hope this helps.

Thanks,

Sri.

Read only

Former Member
0 Likes
910

hi

Use SpliT and concatenate

Read only

Former Member
0 Likes
910

Hello

Try this:


DATA: XTEXT(20).
DATA: CH1(1),
      CH2(1).

CH1 = 'I'.
CH2 = ' '.
XTEXT = 'SAPISGREAT'.

SEARCH XTEXT FOR CH1.
IF SY-SUBRC = 0.
  REPLACE CH1 WITH CH2 INTO XTEXT.
ENDIF.
WRITE XTEXT.

Read only

Former Member
0 Likes
910

Hi,

You can use the following replace statement


data: var type string.
var = 'SAPISGREAT'.
REPLACE ALL OCCURENCES OF 'I' IN var  WITH space into var.

Regards,

Vik

Read only

Former Member
0 Likes
910

hi,

use split starement to split at the specific point.

and the comncatenate it back with the seperated by space.



DATA : var1(20) type c,
             var2(20) type c,
             var3(20) type c,
             var4  type i.

VAR!1 =  SAPISGREAT.

split var1 into var2 var3 at i.

 var4 = srtlen(var2.).

var2 = var2 +0(var4-1).

concatenate var2 var3 into var1 seperated by space.

hope this helps

Regards

RItesh J

Read only

Former Member
0 Likes
910

Hi,

Try this




DATA: name(20) TYPE c VALUE 'SAPISGREAT'.

TRANSLATE name using 'I '.

WRITE name.

Read only

Former Member
0 Likes
910

Hi Rajitha,

the best way to replace the string dynamically with any char is using FM STRING_REPLACE

just give the pattern i.e 'I' in your case

substitute as ' ' and Text as the string..

Its Easy!!

Best of Luck !!

Regards

Ravi

Read only

kesavadas_thekkillath
Active Contributor
0 Likes
910

May be Karthik D would give the exact solution for this