‎2007 Nov 09 10:45 PM
Ok, I need syntax when I am merging tables.
I need to search a particular field and do some logic against it.
For example, field A1 could say "i have no idea how to code this problem" and I would have to search for a BEGINNING phrase "i have no idea..."
If found, A1 = B1 (a different field).
Could someone post syntax on how to search for a phrase within a field?
Would you use the search?
If so, then what would the if statement look like?
‎2007 Nov 09 10:51 PM
You can search it with SEARCH command,
Like this:
REPORT ZTEST_NP.
data: l_text type string,
l_find type string.
l_text = 'i have no idea how to code this problem'.
l_find = 'i have no idea'.
search l_text for l_find.
if sy-subrc = 0.
write: 'found'.
** do your processing.
endif.Regards,
Naimesh Patel
‎2007 Nov 09 10:51 PM
You can search it with SEARCH command,
Like this:
REPORT ZTEST_NP.
data: l_text type string,
l_find type string.
l_text = 'i have no idea how to code this problem'.
l_find = 'i have no idea'.
search l_text for l_find.
if sy-subrc = 0.
write: 'found'.
** do your processing.
endif.Regards,
Naimesh Patel
‎2007 Nov 13 3:29 PM
Hey Naimesh,
If I have multiple phrases to search for, such as if the field contains "this phrase" then do this, if the field contains "this other phrase" then do this, if the field contains "this guy" then do this.
What would the statement look like?
Would you use CASE? Would you just use SEARCH....IF....ENDIF...repeat???
Thanks
‎2007 Nov 13 3:36 PM
Yes I would suggest to make in loop rather doing hardcode:
try this piece of code:
REPORT ZTEST_NP.
DATA: L_TEXT TYPE STRING.
DATA: BEGIN OF IT_FIND OCCURS 0,
FIND TYPE STRING,
END OF IT_FIND.
L_TEXT = 'i have no idea how to code this problem'.
IT_FIND-FIND = 'problem'.
APPEND IT_FIND.
IT_FIND-FIND = 'i have no idea'.
APPEND IT_FIND.
LOOP AT IT_FIND.
SEARCH L_TEXT FOR IT_FIND-FIND.
IF SY-SUBRC = 0.
WRITE: / IT_FIND-FIND,'was found'.
** do your processing.
ENDIF.
ENDLOOP.Regards,
Naimesh Patel
‎2007 Nov 13 5:15 PM
Points to Naimesh. Thanks man. Too bad we dont work together- it would be sweet learning what you know.
‎2007 Nov 13 5:17 PM
‎2007 Nov 09 11:44 PM
Hi
You have to use the String commands like
CP (Contains pattern)
CS(contains string) etc for this purpose
data : str (30) type c,
str1(15) type c.
str = 'i have no idea how to code this problem'.
str1 = 'i have no idea'.
if str CP str1.
....do something...
endif.
if str CS str1.
....do something...
endif.
Regards
Anji