‎2020 Mar 17 12:34 PM
I have two variables like ABC and CDS and have text in those. Just I wanted to compare whether both are having same text or different text. If some characters are match then want to display those match characters...
Let me know any FM...
‎2020 Mar 17 2:16 PM
Hi Himanshu
You may check the following - example
split string2 at space into table data(wordlist).
then loop at wordlist
match( val = <your_searchable_string> regex = <wordlist-word> occ = 1 )
endloopmay need to correct for syntax
‎2020 Mar 17 12:38 PM
‎2020 Mar 17 12:53 PM
‎2020 Mar 17 2:02 PM
I Think CS we can only get contain string.. if exist then true.. but we did not get which string is matched....
‎2020 Mar 17 12:56 PM
Dear Hasan
There are string operations
You can refer to this link
‎2020 Mar 17 1:04 PM
‎2020 Mar 17 1:06 PM
Sorry, I did not get you.
you are not able to open the link?
‎2020 Mar 17 2:05 PM
Checking whether they are same or different should be easy, right ?
But what are your requirements on checking for matches? You need to be more specific what kind of matches your are looking for and what the output should be? Because there can be more than 1 match.
ABC = 'ABKLBYZ'.
CDS = 'ABLKAYZ'.
I 'find' the following matches for above example:
=> What 'matches' are you looking for? Are you just looking for matching prefixes of your variable, which should also be fairly easy, right?
‎2020 Mar 17 2:16 PM
Hi Himanshu
You may check the following - example
split string2 at space into table data(wordlist).
then loop at wordlist
match( val = <your_searchable_string> regex = <wordlist-word> occ = 1 )
endloopmay need to correct for syntax
‎2020 Mar 17 3:04 PM
You mean a "diff" of strings? Eventually look at this other question.
‎2020 Mar 17 3:10 PM
Hi michael.piesche,
as per your example.. i am looking for only AB.....
‎2020 Mar 18 3:26 AM
Thank you for the short clarification on your requirements. Its still not a 100% clear on what the use-case is and what the input paramaters can be, but for now, see my answer above.
As a side note: Please use the comment function for comments to a specific thread, not the answer function to the question itself.
‎2020 Mar 17 3:38 PM
, so, you are only interested in a full match or a matching prefix, correct?In that case, the following coding would be simple and totally sufficient, but might have to tested and definitly be adapted in case your variables abc and cds are are either different length or strings to avoid shortdumps when one variables content is longer than the other. (eg use strlen( var ) to check the length of the content of your variable and only compare against partial prefixes of your variables abs and cds, when the prefix is shorter than the length of the content of your variable).
DATA match LIKE abc. " matching prefix
DATA fullmatchfound TYPE boole_d.
DATA prefixmatchfound TYPE boole_d.
IF abc = cds.
match = abc.
fullmatchfound = abap_true.
ELSE.
sy-subrc = 0.
WHILE sy-subrc = 0.
IF abc(sy-index) = cds(sy-index).
match = abc(sy-index).
prefixmatchfound = abap_true.
ELSE.
sy-subrc = 8.
ENDIF.
ENDWHILE.
ENDIF.Let me know if that helps. (I didnt test it, so let me know if it doesnt compile or whether it throws an unexpected dump)
‎2020 Mar 17 5:57 PM
DATA: lv_abc TYPE c LENGTH 10 VALUE 'ABCDEF',
lv_def TYPE c LENGTH 10 VALUE 'ABCDEFG'.
IF lv_abc CS lv_def AND strlen( lv_abc ) EQ strlen( lv_def ).
WRITE : 'Same string'.
ENDIF.
‎2020 Mar 17 7:12 PM
I created a code that show all the intersection.
types: begin of t_texto,
texto type char10,
end of t_texto.
DATA : x type char10 value 'ABCD',
y TYPE char10 value 'XBCYZ',
z type char10,
n type int2,
n1 type int2,
n2 type int2,
n3 type int2,
t1 type STANDARD TABLE OF t_texto,
r2 type RANGE OF t_texto,
sr like line of r2,
t3 TYPE STANDARD TABLE OF t_texto.
n = strlen( x ).
clear n1.
do n times.
n2 = 1.
while n2 <= n.
z = x+n1(n2).
APPEND z to t1.
add 1 to n2.
n3 = n1 + n2.
if n3 > n.
exit.
ENDIF.
ENDWHILE.
add 1 to n1.
ENDDO.
n = STRLEN( Y ).
clear n1.
DO n TIMES.
n2 = 1.
WHILE n2 <= n.
Z = y+n1(n2).
sr-sign = 'I'.
sr-low = z.
sr-option = 'EQ'.
APPEND sr TO r2.
ADD 1 TO n2.
n3 = n1 + n2.
IF n3 > n.
EXIT.
ENDIF.
ENDWHILE.
ADD 1 TO n1.
ENDDO.
delete t1 where texto not in r2.
LOOP at t1 into z.
write: / z.
ENDLOOP.
‎2020 May 13 3:38 PM
himanshukawatra.02, please follow up on your open question.