sapdev logo background
sapdev logo sapdev logo
Comments

ABAP REPLACE Statement syntax, information and example SAP source code



Return to Statement index



REPLACE

Short Reference

ABAP Syntax:
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].

What does it do? 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
0The search pattern or specified section was replaced by the content of new and the result is available in full in dobj .
2The 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.
4The search pattern in pattern was not found in dobj in the pattern-based search.
8The operands pattern or new do not contain interpretable double-byte characters.

Latest 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 .
Documentation extract taken from SAP system, � Copyright SAP AG. All rights reserved




REJECT
REPLACE_IN_PATTERN




comments powered by Disqus