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] ) ...


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.



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