SAP COUNT FUNCTIONS



Get Example source ABAP code based on a different SAP table
  


• count ABAP_FUNCTION
• count_any_of ABAP_FUNCTION
• count_any_not_of ABAP_FUNCTION

ABAP_STRINGFUNC - count, count_...

ABAP_SYNTAX
1. ... count( val = text ${ sub = substring $}$|${pcre = regex$} $[ case = case$]
$[off = off$] $[ len = len$] ) ...
2. ... count_any_of( val = text sub = substring
$[off = off $] $[len = len$] ) ...
3. ... count_any_not_of( val = text sub = substring
$[off = off $] $[len = len$] ) ...

What does it do?
The built-in search functions count and count_... search text in the same way as the corresponding search functions find and find_..., either in the entire string text or in a subarea defined using off and len for characters specified in substring or for a match with a regular expression specified in regex. Instead of an offset, they return the number of all occurrences.
If the argument pcre is used, regex must contain a PCRE regular expression. A regular expression in PCRE 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 has the type i.



Latest notes:

Besides pcre, 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 result of the following function calls is 1, 3, and 6.
ABEXA 00974
ABAP_EXAMPLE_END

ABAP_EXAMPLE_VX5
The result of the first counting is 2 because the PCRE regular expression handles the surrogate pair in the character string as two characters by default. When counting with a regular expression that is introduced with (*UTF), the result is 1, because the surrogate pair is interpreted as one UTF-16 character.
ABEXA 01492
ABAP_EXAMPLE_END

ABAP_EXAMPLE_ABEXA
String Functions, count, find and match
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:
More information: Exceptions in Regular Expressions.
Runtime error:
REGEX_TOO_COMPLEX
CX_SY_STRG_PAR_VAL
Reason for error:
Substring in sub or regular expression in regex is empty or occurrence in occ is 0.
Runtime error:
STRG_ILLEGAL_PAR