‎2007 Apr 11 12:33 PM
‎2007 Apr 11 12:37 PM
‎2007 Apr 11 12:38 PM
Hi Suneeta,
What exactly are you looking for?
Check this documentation with some examples as well
"Logical Expressions - Comparison Operators for Character-Type Fields
In some cases, the syntax rules that apply to Unicode programs are different than those for non-Unicode programs. See Processing Strings in Unicode Programs.
In the condition " c1 op c2", the comparison operator op between the fields c1 and c2 may be any of the operations listed below, but c1 and c2 must be character- type fields ( C, STRING, N, D, T).
CO (Contains Only):
c1 contains only characters from the string c2.
If c1 or c2 is of type C, the comparison takes into account the full length of the field, including blanks at the end.
comparison.
If c1 is of type STRING and empty, the result of the comparison is always positive.
If c2 is of type STRING and empty, the result of the comparison is always negative, unless c1 is also an empty string.
If the result of the comparison is negative, the field SY-FDPOS contains the offset of the first character in c1 which is not also included 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.
If c1 or c2 is of type C, the comparison takes into account the full length of the field, including blanks at the end.
If c1 or c2 is of type STRING and empty, the result of the comparison is always negative.
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 respective field is of type C.
An empty string c2 (i.e., only blanks with type C, or empty string with type STRING) is included in any string c1, including the empty string itself. On the other hand, there is no non-empty string c2 included in an empty string c1.
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):
The complete string c1 matches the pattern c2 (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".
This allows you to search for:
- characters in upper or lower case
e.g.: c1 CP '#A#b'
- the wildcard characters '*', '+' themselves
e.g.: c1 CP '#' or c1 CP '#+*'
- the escape symbol itself
e.g.: c1 CP '##'
- blanks at the end of c1
e.g.: c1 CP '*# '
If c2 does not contain the wildcard character '*', the shorter field is padded with "soft blanks" to bring it up to the length of the longer field.
Examples:
'ABC' CP 'ABC ' is true,
'ABC ' CP 'ABC' is true,
but
'ABC' CP 'ABC+' is false,
'ABC' CP 'ABC# ' is false,
because a "soft blank" is neither any character ('+') nor a "real" blank ('# ').
The escape symbol does not affect the length of f2 ('A#a#B' still has the length 3).
The comparison is not case-sensitive.
NP (contains No Pattern):
"c1 NP c2" is equivalent to " NOT ( c1 CP c2 )"
c1 does not match c2.
REgards,
Ravi
‎2016 Jun 22 9:06 AM
‎2007 Apr 11 12:38 PM
Hi,
Go through the following documentation
<u>
<b>Comparing Strings:</b></u>
Similarly to the special statements for processing strings, there are special comparisons that you can apply to strings with types C, D, N, and T. You can use the following operators:
<operator> Meaning
CO Contains Only
CN Contains Not only
CA Contains Any
NA contains Not Any
CS Contains String
NS contains No String
CP Matches pattern
NP Does not match pattern
There are no conversions with these comparisons. Instead, the system compares the characters of the string. The operators have the following functions:
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> .
CS (Contains String)
The logical expression
<f1> CS <f2>
is true if <f1> contains the string <f2>. Trailing spaces are ignored and the comparison is not case-sensitive. If the comparison is true, the system field SY-FDPOS contains the offset of <f2> in <f1> . If it is false, SY-FDPOS contains the length of <f1>.
NS (contains No String)
The logical expression
<f1> NS <f2>
is true if <f1> does not contain the string <f2>. Trailing spaces are ignored and the comparison is not 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 <f2> in <f1> .
CP (Contains Pattern)
The logical expression
<f1> CP <f2>
is true if <f1> matches the pattern <f2>. If <f2> is of type C, you can use the following wildcards in <f2>:
for any character string: *
for any single character: +
Trailing spaces are ignored and the comparison is not case-sensitive. If the comparison is true, the system field SY-FDPOS contains the offset of <f2> in <f1> . If it is false, SY-FDPOS contains the length of <f1>.
If you want to perform a comparison on a particular character in <f2>, place the escape character # in front of it. You can use the escape character # to specify
characters in upper and lower case
the wildcard character "" (enter:#)
the wildcard character "" (enter: # )
the escape symbol itself (enter: ## )
blanks at the end of a string (enter: #___ )
NP (contains No Pattern)
The logical expression
<f1> NP <f2>
is true if <f1> does not match the pattern <f2>. In <f2>, you can use the same wildcards and escape character as for the operator CP.
Trailing spaces are ignored and the comparison is not 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 <f2> in <f1> .
DATA: f1(5) TYPE c VALUE <f1>,
f2(5) TYPE c VALUE <f2>.
IF f1 <operator> f2.
WRITE: / 'Vergleich wahr, SY-FDPOS=', sy-fdpos.
ELSE.
WRITE: / 'Vergleich falsch, SY-FDPOS=', sy-fdpos.
ENDIF.
Regards,
Sandhya
‎2007 Apr 11 12:38 PM
Comparing Strings
Similarly to the special statements for processing strings, there are special comparisons that you can apply to strings with types C, D, N, and T. You can use the following operators:
<operator>
Meaning
CO
Contains Only
CN
Contains Not only
CA
Contains Any
NA
contains Not Any
CS
Contains String
NS
contains No String
CP
Contains Pattern
NP
contains No Pattern
There are no conversions with these comparisons. Instead, the system compares the characters of the string. The operators have the following functions:
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> .
CS (Contains String)
The logical expression
<f1> CS <f2>
is true if <f1> contains the string <f2>. Trailing spaces are ignored and the comparison is not case-sensitive. If the comparison is true, the system field SY-FDPOS contains the offset of <f2> in <f1> . If it is false, SY-FDPOS contains the length of <f1>.
NS (contains No String)
The logical expression
<f1> NS <f2>
is true if <f1> does not contain the string <f2>. Trailing spaces are ignored and the comparison is not 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 <f2> in <f1> .
CP (Contains Pattern)
The logical expression
<f1> CP <f2>
is true if <f1> contains the pattern <f2>. If <f2> is of type C, you can use the following wildcards in <f2>:
for any character string *
for any single character +
Trailing spaces are ignored and the comparison is not case-sensitive. If the comparison is true, the system field SY-FDPOS contains the offset of <f2> in <f1> . If it is false, SY-FDPOS contains the length of <f1>.
If you want to perform a comparison on a particular character in <f2>, place the escape character # in front of it. You can use the escape character # to specify
characters in upper and lower case
the wildcard character "" (enter # )
the wildcard character "" (enter # )
the escape symbol itself (enter ## )
blanks at the end of a string (enter #___ )
NP (contains No Pattern)
The logical expression
<f1> NP <f2>
is true if <f1> does not contain the pattern <f2>. In <f2>, you can use the same wildcards and escape character as for the operator CP.
Trailing spaces are ignored and the comparison is not 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 <f2> in <f1> .
DATA: F1(5) TYPE C VALUE <f1>,
F2(5) TYPE C VALUE <f2>.
IF F1 <operator> F2.
WRITE: / 'Comparison true, SY-FDPOS=', SY-FDPOS.
ELSE.
WRITE: / 'Comparison false, SY-FDPOS=', SY-FDPOS.
ENDIF.
The following table shows the results of executing this program, depending on which operators and values of F1 and F2.
<f1>
<operator>
<f2>
Result
SY-FDPOS
'BD '
CO
'ABCD '
true
5
'BD '
CO
'ABCDE'
false
2
'ABC12'
CN
'ABCD '
true
3
'ABABC'
CN
'ABCD '
false
5
'ABcde'
CA
'Bd '
true
1
'ABcde'
CA
'bD '
false
5
'ABAB '
NA
'AB '
false
0
'ababa'
NA
'AB '
true
5
'ABcde'
CS
'bC '
true
1
'ABcde'
CS
'ce '
false
5
'ABcde'
NS
'bC '
false
1
'ABcde'
NS
'ce '
true
5
'ABcde'
CP
'b'
true
1
'ABcde'
CP
'#b'
false
5
'ABcde'
NP
'b'
false
1
'ABcde'
NP
'#b'
true
5
goto sap library if intsalled in ur system and check the above one....
‎2007 Apr 11 1:04 PM
Hi,
I mean,say... you have 2 string weather and whether,Want to check wheather these strings are same or not
‎2007 Apr 11 1:17 PM
In that case you need to use the below operator
CS (Contains String):
c1 contains the character string c2.
Trailing blanks in c1 and c2 are ignored if the respective field is of type C.
An empty string c2 (i.e., only blanks with type C, or empty string with type STRING) is included in any string c1, including the empty string itself. On the other hand, there is no non-empty string c2 included in an empty string c1.
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.
Regards
Anurag
‎2007 Apr 11 1:27 PM
Try this...
DATA:STRING1 TYPE STRING VALUE 'ABCDEFe',
STRING2 TYPE STRING VALUE 'ABCDEF',
MATCH_FOUND TYPE XFLAG..
CALL FUNCTION 'DX_MAP_COMP_STRINGS'
EXPORTING
STRING1 = STRING1
STRING2 = STRING2
IMPORTING
MATCH_FOUND = MATCH_FOUND.
IF MATCH_FOUND EQ 'Y'.
WRITE : / 'Both Strings are equal'.
ELSE.
WRITE : / 'Not Equal'.
ENDIF.
‎2007 Apr 11 1:26 PM
hi sunitha,
try using this code for ur string comparison:
<b>
operators for strings :</b>
<b>operator Meaning</b>
CO Contains only
CN Contains not only
CA Contains any
NA Contains not any
CS Contains string
NS Contains no string
CP Suits pattern
NP Does not suit pattern
<b>
sample code for string comparison :</b>
<b>DATA: f1(5) TYPE c VALUE <f1>,
f2(5) TYPE c VALUE <f2>.
IF f1 <operator> f2.
WRITE: / 'Compare true, SY-FDPOS=', sy-fdpos.
ELSE.
WRITE: / 'Compare false, SY-FDPOS=', sy-fdpos.
ENDIF.</b>
thank u,
reward points if useful,
thasneem.