Just as there are special statements for processing character strings, ABAP contains special compare operators for character-type data types. The following operators compare data objects of the types c, d, n, t, and string.
operator |
Meaning |
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 |
There are no conversions with these comparisons. Instead, the system compares the characters of the string.
For more information on the individual operators, refer to the keyword documentation.
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.
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 |
Since Release 6.10, you can only use relational operators of character-type data types for comparing operands of byte-type data types outside of Unicode programs. To execute suitable comparisons for byte-type objects in Unicode programs, use the relational operators for byte-type data types (BYTE-CO, BYTE-CN, BYTE-CA, BYTE-NA, BYTE-CS, BYTE-NS). See also: Keyword Documentation.