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 characters between < > with single * in variable

Former Member
0 Likes
1,304

Hi Experts ,

I want to replace all characters between < > with *. Data is stored in variable type char255.

Example ,

Suppose variable contains : Wage Type <Wage Type> Not Valid For Interface ID <ID>

I want output as Wage Type * Not Valid For Interface ID *.

Thanks & Regards ,

Jigar Thakkar

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,177

Hi Jigar,

Find the length of the string and use DO...ENDDO statement. Inside the loop, didnt consider the text between < and > and move to another string and add * when > is encountered in the string.


data:
  gv_len type i,
  gv_str type string value 'Wage Type <Wage Type> Not Valid For Interface ID <ID>',
  gv_rep_str type string,
  gv_flag type char1,
  gv_index type sy-index.
gv_len = strlen( gv_str ).
do gv_len times.
gv_index = sy-index - 1.
if gv_str+gv_index(1) = '<'.
gv_flag = 'X'.
continue.
elseif gv_str+gv_index(1) = '>'.
clear gv_flag.
concatenate gv_rep_str '*' into gv_rep_str.
continue.
elseif gv_flag is initial.
concatenate gv_rep_str gv_str+gv_index(1) into gv_rep_str.
endif.
enddo.
write:/ gv_rep_str.

Thanks,

Vinay

Edited by: Vinaykumar G on May 29, 2009 8:04 PM

7 REPLIES 7
Read only

Former Member
0 Likes
1,177

Hi,

Wage Type <Wage Type> Not Valid For Interface ID <ID>

REPLACE  <Wage Type> WITH '*' INTO l_string.
 REPLACE <ID> WITH '*' INTO l_string.

Is this you are looking for ?

Read only

0 Likes
1,177

Hi Avinash ,

No.

Text inside < > is not fixed. So i Can't hardcode values.

I need some dynamic code wich will replace character inside < > with * irrespective of text inside < >.

Thanks & Regards ,

Jigar Thakkar.

Read only

0 Likes
1,177

Hey jigar,

is there any part of the text fix e.g. 'Wage Type'?

regards

Uwe

Read only

Former Member
0 Likes
1,177

Hi jigar,

to replace parts of a variable type string or c do this (example):

REPORT ZREPLACE
Data text type string.

text = 'Token 1, Token 2, Token 3, Token 4'.

while sy-subrc = 0.
   replace ',' with '-' into text.
endwhile.

* to check it is correct
write / text.

Read only

Former Member
0 Likes
1,177

You can create new variables. Put "Wage Type" into the first, "Not Valid For Interface ID" into another and than concatenate them with "*" in between.

Rob

Read only

Former Member
0 Likes
1,178

Hi Jigar,

Find the length of the string and use DO...ENDDO statement. Inside the loop, didnt consider the text between < and > and move to another string and add * when > is encountered in the string.


data:
  gv_len type i,
  gv_str type string value 'Wage Type <Wage Type> Not Valid For Interface ID <ID>',
  gv_rep_str type string,
  gv_flag type char1,
  gv_index type sy-index.
gv_len = strlen( gv_str ).
do gv_len times.
gv_index = sy-index - 1.
if gv_str+gv_index(1) = '<'.
gv_flag = 'X'.
continue.
elseif gv_str+gv_index(1) = '>'.
clear gv_flag.
concatenate gv_rep_str '*' into gv_rep_str.
continue.
elseif gv_flag is initial.
concatenate gv_rep_str gv_str+gv_index(1) into gv_rep_str.
endif.
enddo.
write:/ gv_rep_str.

Thanks,

Vinay

Edited by: Vinaykumar G on May 29, 2009 8:04 PM

Read only

Former Member
0 Likes
1,177

Hi,

first find your length of your field using strlen(field) then you can put * in the first and last field correspondingly.