Application Development and Automation 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: 
Read only

About Strings

Former Member
0 Likes
1,192

Is there any function to compare two strings

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,136

Yes we have

CO, CP , NA , EQ, CS

all these can be used for individual character comparison and for string comparison also..

for more information check this link...

http://help.sap.com/saphelp_47x200/helpdata/en/d3/2e974d35c511d1829f0000e829fbfe/frameset.htm

reward helpful answers..

sai ramesh

10 REPLIES 10
Read only

Former Member
0 Likes
1,137

Yes we have

CO, CP , NA , EQ, CS

all these can be used for individual character comparison and for string comparison also..

for more information check this link...

http://help.sap.com/saphelp_47x200/helpdata/en/d3/2e974d35c511d1829f0000e829fbfe/frameset.htm

reward helpful answers..

sai ramesh

Read only

Former Member
0 Likes
1,136

if u want check if the 2 strings are equal or not, just use

if string1 eq string 2.

Read only

Former Member
0 Likes
1,136

Hi Ravikanth.....

Strings can also be compared with Relational operators like <, > <= >= ........

Just try it once......

Suresh......

Read only

seshatalpasai_madala
Product and Topic Expert
Product and Topic Expert
0 Likes
1,136

Hi,

Try using the FM SOTR_STRING_PARSER_COMPARE.

Regards,

Sesh

Read only

Former Member
0 Likes
1,136

hi

1. CO (Contains Only):

c1 contains only characters in the string c2.

The comparison takes into account the full length of c1,

including blanks at the end.

If the result of the comparison is negative, the system

field SY-FDPOS contains the offset of the first character in

c1 which is not also in c2.

If the result of the comparison is positive, the system

field SY-FDPOS contains the length of c1.

The comparison is case-sensitive.

Examples:

'ABCDE' CO 'XYZ' is false; SY-FDPOS = 0.

'ABCDE' CO 'AB' is false; SY-FDPOS = 2.

'ABCDE' CO 'ABCDE' is true; SY-FDPOS = 5.

CN (Contains Not only):

"c1 CN c2" is equivalent to "NOT ( c1 CO c2 )".

c1 contains not only characters from c2.

If the result of the comparison is positive, the system

field SY-FDPOS contains the offset of the first character in

c1 which is not also in c2.

If the result of the comparison is negative, the system

field SY-FDPOS contains the length of c1.

CA (Contains Any):

c1 contains at least one character from the string c2.

The comparison takes into account the full length of c1,

including blanks at the end.

If the result of the comparison is positive, the system

field SY-FDPOS contains the offset of the first character in

c1 which is also in c2.

If the result of the comparison is negative, the system

field SY-FDPOS contains the length of c1.

The comparison is case-sensitive.

Examples:

'ABCDE' CA 'CY' is true; SY-FDPOS = 2.

'ABCDE' CA 'XY' is false; SY-FDPOS = 5.

NA (contains Not Any):

"c1 NA c2" is equivalent to "NOT ( c1 CA c2 )".

c1 contains no characters from c2.

SY-FDPOS is set accordingly.

CS (Contains String):

c1 contains the character string c2.

Trailing blanks in c1 and c2 are ignored.

If the result of the comparison is positive, the system

field SY-FDPOS contains the offset of the first character of

c2 in c1.

If the result of the comparison is negative, the system

field SY-FDPOS contains the length of c1.

The comparison is not case-sensitive.

Examples:

'ABCDE' CS 'CD' is true; SY-FDPOS = 2.

'ABCDE' CS 'XY' is false; SY-FDPOS = 5.

'ABAAA' CS 'AB ' is true; SY-FDPOS = 0.

' ABC' CS ' AB' is true; SY-FDPOS = 1.

'ABC DEF' CS ' ' is true; but: SY-FDPOS = 0,

since ' ' is interpreted as a trailing blank and is thus

ignored.

NS (contains No String):

"c1 NS c2" is equivalent to "NOT ( c1 CS c2 )".

c1 does not contain c2.

SY-FDPOS is set accordingly.

CP (Contains Pattern):

c1 matches c2.

The pattern c2 can contain ordinary characters and

wildcards.

'*' stands for any character string and '+' denotes any

character.

If the result of the comparison is positive, the system

field SY-FDPOS contains the offset of the first character of

c2 in c1. The wildcard character '*' at the beginning of the

pattern c2 is ignored when determining the value of

SY-FDPOS.

If the result of the comparison is negative, the system

field SY-FDPOS contains the length of c1.

Examples:

'ABCDE' CP 'CD' is true; SY-FDPOS = 2.

'ABCDE' CP '*CD' is false; SY-FDPOS = 5.

'ABCDE' CP '+CD' is true; SY-FDPOS = 0.

'ABCDE' CP '+CD*' is false; SY-FDPOS = 5.

'ABCDE' CP 'BD*' is true; SY-FDPOS = 1.

The character '#' has a special meaning. It serves as an

escape symbol and indicates that the very next character

should be compared "exactly".

Read only

Former Member
0 Likes
1,136

Hi,

You can use = operator to compare strings..

Example

-


DATA: V_STRING1 TYPE STRING.

DATA: V_STRING2 TYPE STRING.

V_STRING1 = 'ABC'.

V_STRING2 = 'ABC'.

IF V_STRING1 = V_STRING2.

WRITE: / 'TRUE'.

ELSE.

WRITE: / 'FALSE'.

ENDIF.

Read only

Former Member
0 Likes
1,136

Hi Ravi,

Yes there are few FM's to compare strings but it depends what is your requirement.

Check

DX_MAP_COMP_STRINGS

/SAPDMC/LSMW_COMP_STRINGS

But better to the string comparison operators as mentioned in the above reply.

Cheers

VJ

Read only

Former Member
0 Likes
1,136

hi

good

USE STRCMP.

thanks

mrutyun^

Read only

Former Member
0 Likes
1,136

Hi ,

Go to transaction ABAPDOCU...

Check 'processing strings' program under

BASIC STATEMENTS -->PROCESS DATA

you willl find all the operations which can be performed on Strings .

Hope this helps .

Thanx .

Read only

Former Member
0 Likes
1,136

Hi..

If your question is answered, please close this thread .

Thanks .