11-07-2013 1:05 PM
Hi Gurus, I have to compare in one table reading another table, two table fields which come from SAP and another system. This is the criteria: Example of data stored on FIELD 1 : ( field Last Name on SAP ) Mariana-Paula Ferray Souza Example of data stored on FIELD 2 : ( string that comes from another system ) Mariana Ferray I need a code that will identify that although field 2 is not equal to field 1 it contains parts of the data from field 1. Thank you, F
11-07-2013 1:06 PM
Hi Gurus,
I have to compare in one table reading another table, two table fields which come from SAP and another system.
This is the criteria: Example of data stored on FIELD 1 : ( field Last Name on SAP )
Mariana-Paula Ferray Souza
Example of data stored on FIELD 2 : ( string that comes from another system )
Mariana Ferray
I need a code that will identify that although field 2 is not equal to field 1 it contains parts of the data from field 1.
Thank you, F
11-07-2013 1:21 PM
Hello,
data g_name1 type string.
data g_name2 type string.
g_name1 = 'Mariana-Paula Ferray Souza'.
g_name2 = 'Mariana Ferray'.
IF g_name2 co g_name1.
write 'The string contains some similarities'.
ENDIF.
Hint: Use the CO keywords.
Thanks and Kind Regards,
Yovish.
11-07-2013 1:24 PM
Hello Fafa,
Please copy paste the below code in Se38 and then do a debug. You would understand what needs to be done.
DATA: field1 TYPE string.
PARAMETERS: field2 TYPE string DEFAULT 'Mariana Ferray'.
DATA: BEGIN OF l_word OCCURS 0,
word(50),
END OF l_word.
field1 = 'Mariana-Paula Ferray Souza'.
*-- whatever text you give in parameter is broken into words
*-- and each word is stored in a line of table.
SPLIT field2 AT ' ' INTO TABLE l_word.
*-- if there is extra spacing between words
*-- then delete the extra lines which does not have any word to compare.
DELETE l_word WHERE word IS INITIAL.
*-- loop for each word and search the word in the string
*-- then do your own processing.
LOOP AT l_word.
SEARCH field1 FOR l_word-word.
IF sy-subrc = 0.
WRITE:/ ' Word present: ', l_word-word.
ELSE.
WRITE:/ ' Word not present: ', l_word-word.
ENDIF.
ENDLOOP.
11-07-2013 1:25 PM
I am not sure I understood you correctly. My field from SAP is a CHAR 40. The other field is a string.
11-07-2013 1:27 PM
Could not do it with the type fields I have. Maybe I am doing something wrong ... will try again
11-07-2013 1:33 PM
Hello,
string or char both work.
run this code my dear friend.
data g_name1(40) type c.
data g_name2 type string.
g_name1 = 'Mariana-Paula Ferray Souza'.
g_name2 = 'Mariana Ferray'.
IF g_name2 co g_name1.
write 'The string contains some similarities'.
ENDIF
USE the RELATIONAL OPERATION CO or CA which means Contains Only and Contains Any respectively in SAP.
In this example g_name1 is of type C and g_name2 is of type string as per your requirements.
Result:
http://scn.sap.com/servlet/JiveServlet/showImage/2-14505313-318881/Snap1438.png
Thanks and Kind Regards,
Yovish.
11-07-2013 1:36 PM
Hello,
DATA lv_inp1 TYPE string VALUE 'Mariana-Paula Ferray Souza'.
DATA lv_inp2 TYPE char40 VALUE 'Mariana Ferray'.
IF lv_inp2 NE lv_inp1.
IF lv_inp2 Co lv_inp1..
WRITE 'The string have same words'.
ENDIF.
ENDIF.
We have some more Comparison Operators for Character-Like Data Types, which you can find on pressing F1 on CO in the statement. IF lv_inp2 Co lv_inp1..
11-07-2013 1:43 PM