12-27-2007 9:05 AM
Hi All,
I would like to know what is the syntax to be used to check if a particular word exists in a sentence. I tried the below, but it is not giving me the desired result. I am checking to see if the word Comp exists in the name & also would like to know is this a case-sensitive search? i.e would Comp be treated differently from comp? if i want the search to check for 'comp' irrespective of the case, how should i do it?
SELECT SINGLE NAME1 FROM KNA1 INTO Y_NAME1
WHERE KUNNR EQ VBRK-KUNRG.
IF Y_NAME1 CA 'Comp'.
Y_TYP_SAL = 'INTERNAL'.
ELSE.
Y_TYP_SAL = 'EXTERNAL'.
ENDIF.
12-27-2007 9:19 AM
IF Y_NAME1 CS 'Comp'.
Y_TYP_SAL = 'INTERNAL'.
ELSE.
Y_TYP_SAL = 'EXTERNAL'.
ENDIF.
Just use this CS in ur comaprision operator .
Vijay
12-27-2007 9:10 AM
Hi,
use the find keyword to search the string
FIND 'Comp' IN Y_NAME1.
if sy-subrc = 0.
sucess
else
fail.
endif.
regards,
siva chalasani.
Reward points if found usefull
12-27-2007 9:11 AM
DATA:
c TYPE STRING,
p(2) TYPE C.
c = 'Everyone knows this'.
p = 'NO'.
FIND p IN c IGNORING CASE.
Try this.
Awrd Points if useful
Bhupal
12-27-2007 9:13 AM
Hi,
To search a character field for a particular pattern, use the SEARCH statement as follows:
SEARCH <c> FOR <str> <options>.
The statement searches the field <c> for <str> starting at position <n1>. If successful, the return code value of SY-SUBRC is set to 0 and SY-FDPOS is set to the offset of the string in the field <c>. Otherwise, SY-SUBRC is set to 4.
<str>----
<pattern>--
Trailing blanks are ignored.
.<pattern>.----
Searches for <pattern>. Trailing blanks are not ignored.
*<pattern>----
A word ending with <pattern> is sought.
<pattern>*----
Searches for a word starting with <pattern>.
Words are separated by blanks, commas, periods, semicolons, colons, question marks, exclamation marks, parentheses, slashes, plus signs, and equal signs.
<option> in the SEARCH FOR statement can be any of the following:
ABBREVIATED
Searches the field <c> for a word containing the string in <str>. The characters can be separated by other characters. The first letter of the word and the string <str> must be
the same.
STARTING AT <n1>
Searches the field <c> for <str> starting at position <n1>. The result SY-FDPOS refers to the offset relative to <n1> and not to the start of the field.
ENDING AT <n2>
Searches the field <c> for <str> up to position <n2>.
AND MARK
If the search string is found, all the characters in the search string (and all the characters in between when using ABBREVIATED) are converted to upper case.
Ex.
DATA STRING(30) VALUE 'This is a little sentence.'.
WRITE: / 'Searched', 'SY-SUBRC', 'SY-FDPOS'.
ULINE /1(26).
SEARCH STRING FOR 'X'.
WRITE: / 'X', SY-SUBRC UNDER 'SY-SUBRC',
SY-FDPOS UNDER 'SY-FDPOS'
SEARCH STRING FOR 'itt '.
WRITE: / 'itt ', SY-SUBRC UNDER 'SY-SUBRC',
SY-FDPOS UNDER 'SY-FDPOS'
SEARCH STRING FOR '.e .'.
WRITE: / '.e .', SY-SUBRC UNDER 'SY-SUBRC',
SY-FDPOS UNDER 'SY-FDPOS'.
SEARCH STRING FOR '*e'.
WRITE: / '*e ', SY-SUBRC UNDER 'SY-SUBRC',
SY-FDPOS UNDER 'SY-FDPOS'.
SEARCH STRING FOR 's*'.
WRITE: / 's* ', SY-SUBRC UNDER 'SY-SUBRC',
SY-FDPOS UNDER 'SY-FDPOS'.
Regards,
Bhaskar
12-27-2007 9:16 AM
Try this logic
parameters: p_matnr like mara-matnr.
data: it_mara like mara occurs 0 with header line.
replace all occurrences of '*' in p_matnr with '%' .
SELECT * FROM mara INTO table it_mara WHERE matnr LIKE p_matnr.
loop at it_mara.
write:/ it_mara-matnr.
endloop.
if usefull reward points helpfull
12-27-2007 9:19 AM
IF Y_NAME1 CS 'Comp'.
Y_TYP_SAL = 'INTERNAL'.
ELSE.
Y_TYP_SAL = 'EXTERNAL'.
ENDIF.
Just use this CS in ur comaprision operator .
Vijay
12-27-2007 9:41 AM
Hi Sniper,
Thank you very much for your help.
Note for Bhaskar: Thanks a lot for that explanatory post
Note for others: Thank you for providing different alternatives, but when i tried with FIND, system prompted a syntax error, it said FIND is undefined.
Keep the good work going.
Cheers & Regards,
Vivek