SAP NetWeaver AS ABAP Release 750, ©Copyright 2016 SAP AG. All rights reserved.
ABAP - Keyword Documentation → ABAP - Reference → Processing Internal Data → Character String and Byte String Processing → Expressions and Functions for String Processing → String Functions → Processing Functions for Character-Like Arguments →replace - Replace Function
Syntax Forms
1. ... replace( val = text [
off = off] [len = len]
with = new ) ...
2. ... replace( val = text {
sub = substring}|{
regex = regex}
with = new [
case = case] [occ = occ] ) ...
Effect
This function replaces a substring of text with the character string specified in new and returns the changed text.
The substring is determined as follows:
new is a character-like expression position. If they have a fixed length, trailing blanks are ignored.
The return code has the type string accordingly.
Notes
Example
The result of the following replacement is "<title>Th<b>i</b>s <b>i</b>s the <i> T<b>i</b>tle</i> </title>". In an HTML line, a particular letter is placed in format tags if it is not itself in a tag.
DATA: html TYPE string,
repl TYPE string.
html = `<title>This is the <i>Title</i></title>`.
repl = `i`.
html = replace( val = html
regex = repl && `(?![^<>]*>)`
with = `<b>$0</b>`
occ = 0 ).
Handleable Exceptions
CX_SY_RANGE_OUT_OF_BOUNDS
CX_SY_REGEX_TOO_COMPLEX
CX_SY_STRG_PAR_VAL