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

Former Member
0 Likes
309

Hi all,

i have 2 strings one with 15 characters(string1) and the other one can have up to 15 characters(string2).

Im trying to figure out how i can check if string2 contains the letters of string1 and as soon as it finds a letter that does not match it sends an error.

However, the characters in the string2 can be in different order.

Thanks in advance!

1 ACCEPTED SOLUTION
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
287

Couple different ways to do this. Here is one solution.



report zrich_0003.

data: string1 type string.
data: string2 type string.
data: offset type i.
data: length type i.

string1 = 'ABCDEFGHI'.
string2 = 'IHGFXEDCBA'.


length = strlen( string2 ).

while sy-subrc  = 0.

  if  offset => length.
    exit.
  endif.

  search string1 for string2+offset(1).
  if sy-subrc <> 0.
    message e001(00) with 'Value not found in string1'.
  endif.

  offset = offset + 1.

endwhile.

Regards,

Rich Heilman

1 REPLY 1
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
288

Couple different ways to do this. Here is one solution.



report zrich_0003.

data: string1 type string.
data: string2 type string.
data: offset type i.
data: length type i.

string1 = 'ABCDEFGHI'.
string2 = 'IHGFXEDCBA'.


length = strlen( string2 ).

while sy-subrc  = 0.

  if  offset => length.
    exit.
  endif.

  search string1 for string2+offset(1).
  if sy-subrc <> 0.
    message e001(00) with 'Value not found in string1'.
  endif.

  offset = offset + 1.

endwhile.

Regards,

Rich Heilman