ABAP Keyword Documentation →  ABAP − Reference →  Program Flow Logic →  Expressions and Functions for Conditions →  log_exp - Logical Expressions →  rel_exp - Predicates →  rel_exp - Predicate Functions →  Predicate functions for character-like arguments → 

rel_exp - contains, contains_..., Predicate Functions

Syntax Forms

1. ... contains( val = text  sub|start|end = substring [case = case]
                [off = off] [len = len] [occ = occ] ) ...

2. ... contains( val = text regex = regex [case = case]
                [off = off] [len = len] [occ = occ] ) ...

3. ... contains_any_of( val = text sub|start|end = substring
                       [off = off] [len = len] [occ = occ] ) ...

4. ... contains_any_not_of( val = text sub|start|end = substring
                           [off = off] [len = len] [occ = occ] ) ...

Effect

These predicate functions provide a truth value for a condition of the argument text.

occ is a numerical expression position of type i and its default value is 1. Specifying a value less than or equal to 0 raises an exception of the class CX_SY_STRG_PAR_VAL.

Notes

‏Relational Operator Predicate Function
o1 CO o2 NOT contains_any_not_of( val = o1 sub = o2 )
o1 CN o2 contains_any_not_of( val = o1 sub = o2 )
o1 CA o2 contains_any_of( val = o1 sub = o2 )
o1 NA o2 NOT contains_any_of( val = o1 sub = o2 )
o1 CS o2 contains( val = to_upper( o1 ) sub = to_upper( o2 ) )
o1 NS o2 NOT contains( val = to_upper( o1 ) sub = to_upper( o2 ) )

Since the relational operators CS and NS are not case-sensitive, the arguments must be processed by the functions to_upper (or to_lower). It should also be noted that the trailing blanks of character-like arguments of fixed length are always ignored in the predicate functions, whereas there are exceptions to this rule for operands of relational operators.

The operators CP and NP can be replaced by the predicate function contains and a suitable regular expression. The differences in case handling must also be respected here. Generally, a simple mapping like in CS and NS is not possible, but is also not usually required.

Example

The IF block is reached in the following code excerpt since neither the first nor the last character in html occur in the system field sy-abcde.

DATA html TYPE string.

html = '<body>Text</body>'.

IF contains_any_not_of( val = to_upper( html ) start = sy-abcde ) AND
   contains_any_not_of( val = to_upper( html ) end   = sy-abcde ).
  ...
ENDIF.

Exceptions

Catchable Exceptions

CX_SY_RANGE_OUT_OF_BOUNDS

CX_SY_REGEX_TOO_COMPLEX

CX_SY_STRG_PAR_VAL