SAP CONTAINS FUNCTIONS



Get Example source ABAP code based on a different SAP table
  


• contains ABAP_FUNCTION
• contains_any_of ABAP_FUNCTION
• contains_any_not_of ABAP_FUNCTION
• occ contains function

ABAP_RELEXP - contains, contains_...

ABAP_SYNTAX
1. ... contains( val = text sub$|start$|end = substring $[ case = case$]
$[off = off$] $[ len = len$] $[occ = occ$] ) ...
2. ... contains( val = text pcre$|xpath = 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$] ) ...

What does it do?
These built-in predicate functions return a truth value for a condition to the argument text.
The variants of the function contains with the parameters sub , start, or end scan a search range defined by off and len in text for matches with the string specified in substring. The return value is true if at least the number of matches specified in occ is found. The search is case-sensitive by default, but this can be overridden using the parameter case. If substring is passed to start or end, the matches must occur directly one after another either at the start or at the end of the search range. sub, on the other hand, allows the matches to occur anywhere in the search range. If substring is empty, an exception of the class CX_SY_STRG_PAR_VAL is raised.
The variants of the function contains with the parameter pcre or xpath scan a search range defined by off and len in text for matches with the regular expression specified in regex .
If the argument pcre is used, regex must contain a PCRE regular expression.
If the argument xpath is used, regex must contain a XPath regular expression. A regular expression in PCRE or XPath syntax is compiled in an extended mode: Most unescaped whitespace (blanks and line breaks) of the pattern are ignored outside character classes and comments can be placed behind #. In order to include whitespace and # in a pattern, they must be escaped or the extended mode must be switched of with (?-x) in the regular expression. The return value is true if at least the number of matches specified in occ is found. The search is case-sensitive by default, but this can be overridden using the parameter case.
The function contains_any_of has the same effect as contains , but does not check for the occurrences of the entire string in substring. Instead, it checks for the individual characters in substring, which is always case-sensitive. The return value is true if text contains at least the set of characters specified in occ. If start or end are specified, the characters must be at the start or at the end of the search range in any order, whereas in sub they can be anywhere.
The function contains_any_not_of has the same effect as contains_any_of but does not require the characters from substring. Instead, it requires any characters that are not in substring.
occ is a numeric 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.



Latest notes:

The parameter occ has a different meaning here than in other functions used for searches.
Besides pcre and xpath, also the obsolete argument regex can be used. Then an obsolete POSIX regular expression must be passed.
NON_V5_HINTS
ABAP_HINT_END

ABAP_EXAMPLE_VX5
The IF block is reached in the following code section, since neither the first nor the last character in html occur in the system field sy-abcde.
ABEXA 00911
ABAP_EXAMPLE_END

ABAP_EXAMPLE_VX5
The following function call checks whether a type c field contains any non-digit character.
ABEXA 01458
ABAP_EXAMPLE_END



Runtime Exceptions



Catchable Exceptions
CX_SY_RANGE_OUT_OF_BOUNDS
Reason for error:
Illegal offset or length specified in off and len.
Runtime error:
STRING_OFFSET_TOO_LARGE
CX_SY_REGEX_TOO_COMPLEX
Reason for error:
See Exceptions in Regular Expressions.
Runtime error:
REGEX_TOO_COMPLEX
CX_SY_STRG_PAR_VAL
Reason for error:
A substring in substring or regular expression in regex is empty or the number of occurrences in occ is less than or equal to 0.
Runtime error:
STRG_ILLEGAL_PAR