SAP MATCH FUNCTIONS



Get Example source ABAP code based on a different SAP table
  


• match ABAP_FUNCTION

ABAP_STRINGFUNC - match
The match function returns a substring of a character-like argument that matches a regular expression.

ABAP_SYNTAX
... match( val = text pcre$|xpath = regex $[ case = case$] $[ occ = occ$] ) ...

What does it do?
The built-in function match searches text for the match specified in occ with the regular expression specified in regex and returns the substring found. The search is case-sensitive by default, but this can be overridden using the parameter case.
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 specify whitespace and # characters 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 string.



Latest notes:

Besides pcre and xpath, the obsolete argument regex can also be used. Then an obsolete POSIX regular expression must be passed.
NON_V5_HINTS
ABAP_HINT_END

ABAP_EXAMPLE_VX5
The following match function returns x2.
ABEXA 01124
ABAP_EXAMPLE_END

ABAP_EXAMPLE_ABEXA
String Functions, count, find and match
ABAP_EXAMPLE_END



Runtime Exceptions



Catchable Exceptions
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:
Regular expression in regex is empty or there are 0 occurrences in occ.
Runtime error:
STRG_ILLEGAL_PAR