Skip to content

ABAP Keyword Documentation →  ABAP - Reference →  Program Flow Logic →  Expressions and Functions for Conditions →  log_exp - Logical Expressions →  rel_exp - Comparison Expressions →  rel_exp - Relational Operators 

rel_exp - Relational Operators for Character-Like Data Types

The following table shows the relational operators for comparisons between character-like operands (single data objects or return values or string expressions) in comparison expressions. The trailing blanks are respected for operands of type string. If not stated differently in the following table, the trailing blanks are ignored for operands of types c, d, n, and t.

|operator|Meaning| |----|----| |CO|Contains Only: True, if operand1 only contains characters from operand2. It is case-sensitive and trailing blanks are respected in both operands. If operand2is of type string and initial, then the relational expression is false, exceptif operand1 is also of type string and initial.If operand1 has the type string and is initial,the relational expression is always true, regardless of operand2. If thecomparison is true, sy-fdpos contains the offset of the first character inoperand1 that is not contained in operand2. Ifthe comparison is true, sy-fdpos contains the length of operand1.| |CN|Contains Not Only: True if a relational expression with CO is false,that is, if operand1 contains not only characters from operand2.sy-fdpos is set in the same way as for CO. Ifthe comparison is true, sy-fdpos contains the offset of the first characterin operand1 that is not contained in operand2.If the comparison is false, sy-fdpos contains the length of operand1.| |CA|Contains Any: True, if operand1 contains at least one character fromoperand2. It is case-sensitive and trailing blanks are respected in bothoperands. If operand1 or operand2 are of the typestring and initial, the relational expression is always false. If resultof the comparison is positive, sy-fdpos contains the offset of the firstcharacter in operand1 that is also contained in operand2.If the comparison is false, sy-fdpos contains the length of operand1.| |NA|Contains Not Any: True, if a relational expression with CA is false,that is if operand1 does not contain any characters from operand2.If the comparison is false, sy-fdpos contains the offset of the first characterin operand1 that is also contained in operand2.If the comparison is true, sy-fdpos contains the length of operand1.| |CS|Contains String: True, if the content of operand2 is contained in operand1. It is not case-sensitive and trailing blanks in the left operand are respected. Ifoperand1 is of type string and initial, or oftype c and contains only blank characters, the relational expression is false,unless operand2 is also of type string and initial,or of type c and only contains blank characters. In this case, the relationalexpression is always true. If the comparison is true, sy-fdpos contains theoffset of operand2 in operand1. If the comparison is false, sy-fdpos contains the length of operand1.| |NS|Contains No String: True, if a relational expression with CS is false,that is if operand1 does not contain the content of operand2.If the comparison is false, sy-fdpos contains the offset of operand2in operand1. If the comparison is true, sy-fdpos contains the length of operand1.| |CP|Covers Pattern: True, if the content of operand1 fits the pattern inoperand2. Wildcard characters can be used to create the operand2pattern, where "" represents any character string (including a blankstring) and "+" represents any character. It is not case-sensitive. Trailingblanks in the left operand are respected. If the comparison is true, sy-fdposcontains the offset of operand2 in operand1. Here,leading wildcard characters "" in operand2are ignored if operand2 also contains other characters. If the comparisonis false, sy-fdpos contains the length of operand1. Characters in operand2 can be selected for direct comparisons by prefixing them with theescape character"#". For characters flagged in this way in operand2, the operatoris case-sensitive. Also, wildcard characters and the escape character are not subject to special handling and trailing blanks are relevant.| |NP|No Pattern: True, if a relational expression with CP is false, that is,if operand1 does not fit the pattern operand2.If the comparison is false, sy-fdpos contains the offset of operand2in operand1. Here, leading wildcard characters "*"in operand2 are ignored if operand2 also containsother characters. If the comparison is true, sy-fdpos contains the length of operand1.|

Other versions: 7.31 | 7.40 | 7.54


Notes

  • The operators CP and NP use multiple wildcard characters "*" in a row in the same way as a single "*" character. The wildcard character "+" does not represent a blank string.

  • The statement FIND and the search functions find can be quicker than the relational operator CS by some magnitude.

Example

Searches for HTML tags in a text using operator CP. This search finds the first HTML tag "<i> " at offset 8. Note that it is not enough to specify a search pattern "<>", since CP stands for Covers Pattern, and not for Contains Pattern. The example also shows that leading wildcard characters "" in the string are ignored in sy-fdpos so that the occurrence found by this search can be identified.

DATA html TYPE string. 

html = `This is <i>italic</i>!`. 

IF html CP '*<*>*'. 
  cl_demo_output=>display_text( |Found HTML tag at { sy-fdpos }| ). 
ENDIF.