ABAP Keyword Documentation → ABAP − Reference → Processing Internal Data → Character String and Byte String Processing → Statements for Character String and Byte String Processing → REPLACE → REPLACE pattern IN
REPLACE - pattern
Other versions: 7.31 | 7.40 | 7.54
Syntax
... {[SUBSTRING] substring} | {REGEX regex} ... .
Effect
Defines a search pattern for the statements
REPLACE and REPLACE IN TABLE.
-
If
substringis specified, the exact substring specified insubstringis found. The optional additionSUBSTRINGcan be specified in front ofsubstringfor extra emphasis. -
If
REGEXis specified, the substring is found that matches aregular expressionspecified inregex.
substring and a directly specified regex 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 substring in question in accordance with the information specified after WITH.
Note
A regular expression can be have correct syntax, but be too complex for the execution of the statement
REPLACE, which raises a handleable exception of the class CX_SY_REGEX_TOO_COMPLEX. See
Exceptions in Regular Expressions.
Example
Replaces the substring "all" with "er".
DATA(str) = `Hallo`.
REPLACE SUBSTRING `all` IN str WITH `er`.
cl_demo_output=>display( str ).
Example
The following replacement with regular expression \D removes all non-digits from a string.
DATA(str) = `4 Apples + 2 Oranges`.
REPLACE ALL OCCURRENCES OF REGEX `\D` IN str WITH ``.
cl_demo_output=>display( str ).