ABAP Keyword Documentation → ABAP - Short Reference
REPLACE - Short Reference
Other versions: 7.31 | 7.40 | 7.54
Syntax
REPLACE { { [{FIRST OCCURRENCE}|{ALL OCCURRENCES OF}] 
            {[SUBSTRING] substring} | {REGEX regex} IN 
            { {[SECTION [OFFSET off] [LENGTH len] OF] dobj} 
            | {TABLE itab [FROM lin1 [OFFSET off1]] 
                          [TO   lin2 [OFFSET off2]]} } 
            WITH new 
            [IN {CHARACTER|BYTE} MODE] 
            [{RESPECTING|IGNORING} CASE] 
            [REPLACEMENT COUNT  rcnt] 
            { {[REPLACEMENT OFFSET roff] 
               [REPLACEMENT LENGTH rlen] 
               [REPLACEMENT LINE   rlen]} 
            | [RESULTS result_tab|result_wa] } } 
        | { SECTION [OFFSET off] [LENGTH len] OF dobj 
            WITH new 
            [IN {CHARACTER|BYTE} MODE] } }. 
Effect
Replaces character- or byte strings in a character- or byte-type data object dobj
or in an internal table itab with the content of new.
Determination of the characters or bytes to be replaced using a search for substrings or regular expressions or by specifying the offset and length directly.  
Additions
- 
{FIRST OCCURRENCE}|{ALL OCCURRENCES OF}
 [SECTION [OFFSET off] [LENGTH len] OF]
 Defines whether the first or all found locations are replaced with the content of data objectnew. You can restrict the search area to the section from the offset specified inoff. The length of this offset is specified inlen.
- 
{[SUBSTRING] substring} | {REGEX regex}
 Defines whether a substringsubstringor a regular expressionregexis searched for and replaced.
- 
SECTION [OFFSET off] [LENGTH len] OF
 Specifies a section ofdobjfrom the offset specified inoffand the length specified inlen. Either the section to be searched or the section to be replaced.
- 
TABLE itab [FROM lin1 [OFFSET off1]] [TOlin2 [OFFSET off2]]
 Replacement in an internalitabwith restriction of the search area to the section as of the row specified inlin1with the offset specified in off1 up to the row specified inlin2with the offset specified inoff2.
- 
IN {CHARACTER|BYTE} MODE
 Determines character- or byte string processing.
- 
{RESPECTING|IGNORING} CASE
 Determines whether uppercase/lowercase is respected during the search.
- 
REPLACEMENT COUNT rcnt
 Provides the number count of replacements inrcnt.
- 
REPLACEMENT LINE rlin
 Provides the table row of the last replacement inrlin.
- 
REPLACEMENT OFFSET roff
 Provides the offset of the last replacement inroff.
- 
REPLACEMENT LENGTH rlen
 Provides the length of the last replacement inrlen.
- 
RESULTS result_tab|result_wa
 Provides the attributes of all replaced parts or the last replaced part in an internal tableresult_tabor a structureresult_waof type MATCH_RESULTS.