Ansicht
Dokumentation

ABENPREDICATE_FUNCTIONS_STRINGS - PREDICATE FUNCTIONS STRINGS

ABENPREDICATE_FUNCTIONS_STRINGS - PREDICATE FUNCTIONS STRINGS

Addresses (Business Address Services)   Addresses (Business Address Services)  
This documentation is copyright by SAP AG.
SAP E-Book

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 return a truth value for a condition of 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 subsequence specified in substring. The return value is true if at least the number of matches specified in occ are found. The search is case-sensitive by default; however, you can override this using the parameter case. If substring is passed to start or end, the matches must occur directly after each other either at the start or end of the search range; sub allows the matches to occur anywhere in the search range.
  • The variants of the function contains with the parameter regex scan a search range defined by off and len in text for matches with the regular expression specified in regex. The return value is true if at least the number of matches specified in occ are found. The search is case-sensitive by default; however, you can override this using the parameter case.
  • The function contains_any_off 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; this is always case-sensitive. The return value is true if text contains at least the number of individual characters specified in occ. If start or end is specified, the characters can be in any order at the start or end of the search range. sub allows them to be anywhere.
  • The function contains_any_not_off has the same effect as contains_any_off, but does not require the characters from substring; instead, it requires any characters that are not in substring.

occ is a numerical expression position with a default value of 1. If the value specified is less than or equal to 0, an exception of class CX_SY_STRG_PAR_VAL is raised.

Notes

  • The occ parameter is used slightly differently here than in other functions in which a search takes place.
Comparison 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 comparison operators CS and NS are not case-sensitive, the arguments must be processed by the functions to_upper (or to_lower). You should also note that the closing blank characters of character-like arguments of fixed length are never taken into account in the predicate functions, whereas there are exceptions to this rule for operands of comparison 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 or 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 occurs 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.





BAL Application Log Documentation   General Material Data  
This documentation is copyright by SAP AG.

Length: 8747 Date: 20240425 Time: 034442     sap01-206 ( 139 ms )