Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

use of the following keywords

Former Member
0 Kudos

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

1 ACCEPTED SOLUTION

venkat_o
Active Contributor
0 Kudos

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

2 REPLIES 2

venkat_o
Active Contributor
0 Kudos

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

Former Member
0 Kudos

Hi,

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

Thanks,

Sriram Ponna.