Skip to Content
author's profile photo Former Member
Former Member

String search syntax

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.

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

5 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Dec 27, 2007 at 09: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

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      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

  • author's profile photo Former Member
    Former Member
    Posted on Dec 27, 2007 at 09: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

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Dec 27, 2007 at 09: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

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Dec 27, 2007 at 09: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>----


    Function

    <pattern>--


    Searches for <pattern> (any sequence of characters).--


    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

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Dec 27, 2007 at 09: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

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.