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 MANUPULATION

Former Member
0 Likes
762

HI Gurus,

I am in need of a help for comparison of two strings...

A lot of operators and function modules are provided by SAP but my requirement is little fuzzy.....

Eg:

string1 = how is everybody doing

string2 = doing is

My requirement is to get the string comparisons true.....

Unfortunately all string manupulation operators and function modules are giving sy-subrc ne 0.

So in short I need to compare a group of words in a String and should return true if the words get matched in any order

Is there any function modules available for this???

Any help on this is highly appreciated.....

1 ACCEPTED SOLUTION
Read only

awin_prabhu
Active Contributor
0 Likes
721

Hi,

Check this simple code. Will help u.


  DATA:itab TYPE TABLE OF string,
       itab1 TYPE TABLE OF string,
       wa TYPE string.

  PARAMETERS: string1 TYPE string LOWER CASE,
              string2 TYPE string LOWER CASE.

  SPLIT string1 AT space INTO TABLE itab.

  LOOP AT itab INTO wa.
    IF string2 CS wa.                 " Use CS (Contains String) operator
      APPEND wa TO itab1.
    ENDIF.
  ENDLOOP.

  WRITE: 'Matched words between 2 strings:'.
  LOOP AT itab1 INTO wa.
    WRITE:/ wa.
  ENDLOOP.

Thanks.

7 REPLIES 7
Read only

guillaume-hrc
Active Contributor
0 Likes
721

Hi,

I don't think it exists out of the box.

But, what you ask is simply testing the string several times, isn't it ?

IF string1 CP '*is*' AND string1 CP '*doing*' ...

Best regards,

Guillaume

Read only

asik_shameem
Active Contributor
0 Likes
721

You can acheive this by making the string into table using SPLIT command.

SPLIT string1 AT space INTO TABLE itab1.
SPLIT string2 AT space INTO TABLE itab2.

Compare itab1 and itab2 for each word.

LOOP AT itab1.
  READ TABLE itab2.
...
ENDLOOP.

Read only

0 Likes
721

you will just need to split your string2 as mentioned above.

Loop throuhg this table and do a CS of each word in string1.

Read only

former_member186741
Active Contributor
0 Likes
721

data t2 type table of string.

data t2s type string.

data istrue type flag.

  • put string2 into a table of words

split string2 at space into table t2.

*initialise true flag to 'ON'

istrue = 'X".

  • loop through all words in string2

loop at t2 into t2s.

  • if the current string2 word is not in string...

if string1 ns t2s.

*... set true flag OFF

clear istrue.

*... leave the loop

exit.

endif.

endloop.

  • if ISTRUE is not blank all words in string2 are in string1

Read only

awin_prabhu
Active Contributor
0 Likes
722

Hi,

Check this simple code. Will help u.


  DATA:itab TYPE TABLE OF string,
       itab1 TYPE TABLE OF string,
       wa TYPE string.

  PARAMETERS: string1 TYPE string LOWER CASE,
              string2 TYPE string LOWER CASE.

  SPLIT string1 AT space INTO TABLE itab.

  LOOP AT itab INTO wa.
    IF string2 CS wa.                 " Use CS (Contains String) operator
      APPEND wa TO itab1.
    ENDIF.
  ENDLOOP.

  WRITE: 'Matched words between 2 strings:'.
  LOOP AT itab1 INTO wa.
    WRITE:/ wa.
  ENDLOOP.

Thanks.

Read only

0 Likes
721

Thanks for all!!!.....The samples code worked for me........

Read only

0 Likes
721

Well.. People like spoon feeding..!