Skip to content

ABAP Keyword Documentation →  ABAP - Reference →  Program Flow →  Expressions and Functions for Logical Expressions →  log_exp - Logical Expressions →  log_exp - Comparisons →  log_exp - Relational Operators 

log_exp - Comparison Operators for Character-Like Data Types

The following table shows comparison operators for comparisons between character-like operands. 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 logical expression is false, exceptif operand1 is also of type string and initial.In this case, the logical expression is always true. If the comparison is true, sy-fdposcontains the offset of the first character in operand1 that is not containedin operand2. If the comparison is true, sy-fdpos contains the length of operand1.| |CN|Contains Not Only: True if a logical expression with CO is false, thatis, 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 is of type string and initial, the logical expression is always false. If result of the comparison is positive,sy-fdpos contains the offset of the first character in operand1that is also contained in operand2. If the comparison is false, sy-fdpos contains the length of operand1.| |NA|Contains Not Any: True, if a logical expression with CA is false, thatis if operand1 does not contain any characters from operand2.If the result of the comparison is negative, sy-fdpos contains the offsetof the first character in 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 logical 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 logicalexpression 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 logical expression with CS is false, thatis 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 blank string) and "+" represents anycharacter. It is not case-sensitive. Trailing blanks in the left operand are respected. If the comparisonis true, sy-fdpos contains the offset of operand2in operand1, whereby leading wildcard characters "" in operand2are ignored if operand2 also contains other characters. If the comparisonis false, sy-fdpos contains the length of operand1. You can select characters in operand2 for a direct comparison by adding theescape symbol"#" beforethe required characters. For characters flagged in this way in operand2,the operator is case-sensitive. Also, wildcard characters and the escape symbol are not subject to special handling and trailing blanks are relevant.| |NP|No Pattern: True, if a logical 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, whereby leading wildcard characters "*" in operand2are ignored if operand2 also contains other 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 comparison operator CS by some magnitude.

Example

Search 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 '*<*>*'. 
  WRITE: / 'Found HTML tag at', sy-fdpos. 
ENDIF.