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

String operation to replace some text

Former Member
0 Likes
1,494

I have a string MIDDGBPP##SCHNRK22. I want to replace text MIDDGBPP with some other text.

The problem is that I am not able to find out the length of text in before ## signes.

y_v_str = 'MIDDGBPP##SCHNRK22'.

if y_v_str CS '##'.

y_v_offset = sy-fdpos.

endif.

Above code does not update the sy-fdpos variable. It can not find the ## sign in the y_v_str.

How to get length of the first part before ##?

Please provide code if possible.

8 REPLIES 8
Read only

Former Member
0 Likes
1,163

Hi,

if you just want to replace the text:

replace all occurrences of 'MIDDGBPP' with 'new text' in lv_string.

grtz,

Koen

Edited by: Koen Labie on Feb 19, 2008 10:34 AM

Read only

Former Member
0 Likes
1,163

try to split the text at ## and then use strlen on the first part

y_v_str = 'MIDDGBPP##SCHNRK22'.

split y_v_str at '##' into v_first v_second.

v_length = strlen( v_first ). " v_length contains the length

Read only

0 Likes
1,163

split y_v_str1b at '##' into y_v_first y_v_second.

does not work...

It does not find out the ## signes and y_v_first and y_v_second remains empty.

Read only

Former Member
0 Likes
1,163

Hi Suhas,

U can use -

REPLACE 'MIDDGBPP' IN y_v_str WITH 'XXXX'.

Read only

0 Likes
1,163

first text is of variable length

Read only

Former Member
0 Likes
1,163

Hi,

Check the below code...

y_v_str = 'MIDDGBPP##SCHNRK22'.

split y_v_str at '##' into v_str1 v_str2.

v_length = strlen( v_str1 ).

y_v_str(v_length) = '<your own text>'.

Rgds,

Bujji

Read only

vinod_vemuru2
Active Contributor
0 Likes
1,163

Hi try doing like this.

SEARCH y_v_str FOR '##'.

CHECK sy-subrc IS INITIAL.

w_fdpos = sy-fdpos.

MOVE owntext TO y_v_str+0(w_fdpos).

In this case sy-fdpos will be set to 8. So u can replace ur first 8 characters by ur own text

Thanks,

Vinod.

Edited by: Vinod Vemuru on Feb 19, 2008 3:27 PM

Read only

Former Member
0 Likes
1,163

thanks