SAP REPLACE PATTERN ABAP Statements



Get Example source ABAP code based on a different SAP table
  


• SUBSTRING REPLACE
• REGEX REPLACE
• PCRE REPLACE

REPLACE, pattern
Short Reference

ABAP_SYNTAX
... ${$[SUBSTRING$] substring$}
$| ${PCRE pcre$}$|${REGEX regex_ref$} ... .

What does it do?
Defines a search pattern for the statements REPLACE and REPLACE IN TABLE.
If substring is specified, the exact substring specified in substring is searched for. The optional addition SUBSTRING can be specified in front of substring for emphasis.
If PCRE or REGEX is specified, the substring that matches a regular expression specified in pcre or regex_ref is searched for.
PCRE denotes a PCRE regular expression in a character string pcre. The 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 # into a pattern, they must be escaped or the extended mode must be switched of with (?-x) in the regular expression.
REGEX denotes a any regular expression supported by ABAP represented by an instance of the system class CL_ABAP_REGEX referenced by a reference variable regex_ref.
substring and pcre are character-like expression positions. The syntax and semantics are the same as in the definition of a search pattern for the statement FIND. The statement REPLACE replaces the found substring in accordance with the specification after WITH.



Latest notes:

Instances of CL_ABAP_REGEX for all kinds of regular expressions, PCRE, POSIX, XPath and XSD can be used with the addition REGEX. This circumvents the restriction that regular expressions of XPath and XSD syntax cannot be specified directly as character strings.
When using CL_ABAP_REGEX, the extended mode option can be switched by a parameter.
A regular expression can have correct syntax, but be too complex for the execution of the statement REPLACE, which raises a catchable exception of the class CX_SY_REGEX_TOO_COMPLEX. See Exceptions in Regular Expressions.
Behind REGEX, also a character-like operand posix can be specified, that contains a valid POSIX regular expression. This variant is obsolete.
NON_V5_HINTS
ABAP_HINT_END

ABAP_EXAMPLE_VX5
Replacement of the substring all with er.
ABEXA 00556
ABAP_EXAMPLE_END

ABAP_EXAMPLE_VX5
The following replacement with regular expression D removes all non-digits from a string.
ABEXA 00557
ABAP_EXAMPLE_END

Return to menu