Get Example source ABAP code based on a different SAP table
ID REPLACE • REPLACE ABAP Statement • WITH REPLACE
REPLACE> Short Reference >
ABAP_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$].>
What does it do? This statement replaces characters or bytes of the variable dobj> with characters or bytes of the operand new>, which is a character-like expression position>. Here, a distinction is made between pattern-based and position-based replacements. When the replacement is performed, an interim result without a length limit is created implicitly and passed to the data object dobj>. If the length of the interim result is longer than the length of dobj>, data objects of fixed length are truncated on the right. If the length of the interim result is shorter than the length of dobj >, data objects of fixed length are padded on the right with blanks or hexadecimal zeros. Data objects of variable length are adjusted accordingly. If the interim result is truncated during the assignment, sy-subrc> is set to 2. In character string processing, the trailing blanks are respected for data objects dobj> of fixed length. For new> the closing blanks are ignored.
ABAP_EXAMPLE_VX5 The simplest form of the statement REPLACE>. ABEXA 00544 ABAP_EXAMPLE_END 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. BEGIN_SECTION SAP_INTERNAL_HINT The former value 8 for illegal double byte characters is not set any more since only Unicode is supported now. END_SECTION SAP_INTERNAL_HINT
Latest notes:
The statement REPLACE IN TABLE>> can be used to make replacements in internal tables.
To replace parts of a character string in an operand position, a replace function> can be used that includes some of the functions of the statement REPLACE>. NON_V5_HINTS
These forms of the statement REPLACE> replace the following obsolete form: REPLACE substring WITH new INTO dobj ... >> ABAP_HINT_END