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

use of the following keywords

hi

can any body explain me the use of the following keywords with examples

shift

condense

replace

search

and he following operators also with examples

co contains only

cn contains not only

ca contains any

cn contains not any

regards

srinivas

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

2 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Apr 12, 2008 at 07:45 AM

    Hi srinivas, Please Check each statement with example. All the key words you have mentioned are related Character string operations. SHIFT :It shifts the contents of a character field. Syntax:

    SHIFT <char_field>[BY <n> PLACES] [<mode>]
    . <mode> = LEFT or RIGHT or CIRCULAR Example.
    DATA: T(10) VALUE 'abcdefghij',
    STRING LIKE T.
    
    STRING = T.
    WRITE STRING.
    
    SHIFT STRING.
    WRITE / STRING.
    
    STRING = T.
    SHIFT STRING BY 3 PLACES LEFT.
    WRITE / STRING.
    
    STRING = T.
    SHIFT STRING BY 3 PLACES RIGHT.
    WRITE / STRING.
    
    STRING = T.
    SHIFT STRING BY 3 PLACES CIRCULAR.
    WRITE / STRING.
    
    Output: 
    
    abcdefghij
    
    bcdefghij
    
    defghij
    
       abcdefg
    
    defghijabc
    
    CONDENSE:statement deletes redundant spaces from a string. syntax:
    CONDENSE <c> [NO-GAPS].
    example:
    DATA: STRING(25) VALUE ' one two three four',
    LEN TYPE I.
    
    LEN = STRLEN( STRING ).
    WRITE: STRING, '!'.
    WRITE: / 'Length: ', LEN.
    
    CONDENSE STRING.
    LEN = STRLEN( STRING ).
    WRITE: STRING, '!'.
    WRITE: / 'Length: ', LEN.
    
    CONDENSE STRING NO-GAPS.
    LEN = STRLEN( STRING ).
    WRITE: STRING, '!'.
    WRITE: / 'Length: ', LEN.
    
    Output: 
    
    one two three four !
    
    Length:           25
    
    one two three four !
    
    Length:           18
    
    onetwothreefour !
    
    Length:           15
    REPLACE:To replace a string in a field with a different string. syntax.
    REPLACE <str1> WITH <str2> INTO <c> [LENGTH <l>].
    
    example:
    DATA: T(10) VALUE 'abcdefghij',
    STRING LIKE T,
    STR1(4) VALUE 'cdef',
    STR2(4) VALUE 'klmn',
    STR3(2) VALUE 'kl',
    STR4(6) VALUE 'klmnop',
    LEN TYPE I VALUE 2.
    
    STRING = T.
    WRITE STRING.
    
    REPLACE STR1 WITH STR2 INTO STRING.
    WRITE / STRING.
    
    STRING = T.
    REPLACE STR1 WITH STR2 INTO STRING LENGTH LEN.
    WRITE / STRING.
    
    STRING = T.
    REPLACE STR1 WITH STR3 INTO STRING.
    WRITE / STRING.
    
    STRING = T.
    REPLACE STR1 WITH STR4 INTO STRING.
    WRITE / STRING.
    
    The output appears as follows:
    
    abcdefghij
    
    abklmnghij
    
    abklmnefgh
    
    abklghij
    
    abklmnopgh
    SEARCH:To search a character field for a particular pattern. Syntax.
    SEARCH <c> FOR <str> <options>.
    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'.
    
    Output: 
    
    SEARCHED SY-SUBRC SY-FDPOS
    
    X            4        0
    
    itt          0       11
    
    .e .         0       15
    
    *e           0       10
    
    s*           0       17
    
    co contains only cn contains not only ca contains any cn contains not any are related to character String comparison operators. Check the following . CO (Contains Only) The logical expression <f1> CO <f2> is true if <f1> contains only characters from <f2>. The comparison is case-sensitive. Trailing blanks are included. If the comparison is true, the system field SY-FDPOS contains the length of <f1>. If it is false, SY-FDPOS contains the offset of the first character of <f1> that does not occur in <f2> . CN (Contains Not only) The logical expression <f1> CN <f2> is true if <f1> does also contains characters other than those in <f2>. The comparison is case-sensitive. Trailing blanks are included. If the comparison is true, the system field SY-FDPOS contains the offset of the first character of <f1> that does not also occur in <f2>. If it is false, SY-FDPOS contains the length of <f1>. CA (Contains Any) The logical expression <f1> CA <f2> is true if <f1> contains at least one character from <f2>. The comparison is case-sensitive. If the comparison is true, the system field SY-FDPOS contains the offset of the first character of <f1> that also occurs in <f2> . If it is false, SY-FDPOS contains the length of <f1>. NA (contains Not Any) The logical expression <f1> NA <f2> is true if <f1> does not contain any character from <f2>. The comparison is case-sensitive. If the comparison is true, the system field SY-FDPOS contains the length of <f1>. If it is false, SY-FDPOS contains the offset of the first character of <f1> that occurs in <f2> . I hope that it helps you. Regards, Venkat.O

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Apr 12, 2008 at 07:16 PM

    Hi,

    Please refer ABAPDOCU TCode, you will get an idea about all the key words with necessary examples.

    Thanks,

    Sriram Ponna.

    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.