ABAP Keyword Documentation → ABAP - Reference → Processing Internal Data → Character String and Byte String Processing → Statements for Character String and Byte String Processing
REPLACE
Other versions: 7.31 | 7.40 | 7.54
Syntax Forms
Pattern-Based Replacement
1. REPLACE [{FIRST OCCURRENCE}|{ALL OCCURRENCES} OF]
pattern
IN [section_of] dobj WITH new
[IN {CHARACTER|BYTE} MODE]
[replace_options].
Position-Based Replacement
2. REPLACE SECTION [OFFSET off] [LENGTH len] OF dobj WITH new
[IN {CHARACTER|BYTE} MODE].
Effect
This statement replaces characters or bytes of the variable dobj
with characters or bytes of the operand new
. This operand is a
character-like expression position. Here, there is a difference between pattern-based and position-based replacements.
When the replacement is performed, an interim result without a length limit is generated implicitly
and passed to the data object dobj
. If the length of the interim result is
longer than the length of dobj
, the object is truncated on the right in the
case of data objects of fixed length. If the length of the interim result is shorter than the length
of dobj
, data objects of fixed length are filled on the right with blanks
or hexadecimal zeroes. Data objects of variable length are adjusted accordingly. If data is truncated on the right when the interim result is assigned, sy-subrc
is set to 2.
During string processing with data objects dobj
of fixed length, the closing blank is not ignored; in the case of new
it is ignored.
System fields
sy-subrc | Meaning |
---|---|
0 | The search pattern or specified section was replaced by the content of new and the result is available in full in dobj . |
2 | The search pattern or specified section was replaced by the content of new in dobj and the result of the replacement was truncated on the right. |
4 | The search pattern in pattern was not found in dobj in the pattern-based search. |
8 | The operands pattern or new do not contain interpretable double-byte characters. |
Notes
-
The
REPLACE IN TABLE
statement can be used to make replacements in internal tables. -
These forms of the statement
REPLACE
replace the following obsolete form:
REPLACE substring WITH new INTO dobj ...
-
To replace parts of a character string in an operand position, you can use a
replace function that includes some of the functions of the statement
REPLACE
.