Replace in ABAP Strings
Details
- Details
- Category: ABAP
- Created on Tuesday, 29 January 2013 09:32
- Last Updated on Tuesday, 29 January 2013 10:26
- Published on Tuesday, 29 January 2013 09:32
- Written by Administrator
- Hits: 56389
Pattern-based replacement
1. REPLACE [{FIRST OCCURRENCE}|{ALL OCCURRENCES} OF]
pattern
IN [section_of] dobj WITH new
[IN {BYTE|CHARACTER} MODE]
[{RESPECTING|IGNORING} CASE]
[REPLACEMENT COUNT rcnt]
{ {[REPLACEMENT OFFSET roff]
[REPLACEMENT LENGTH rlen]}
| [RESULTS result_tab|result_wa] }.
Position-based replacement
2. REPLACE SECTION [OFFSET off] [LENGTH len] OF dobj WITH new
[IN {BYTE|CHARACTER} MODE].
Effect
This statement replaces characters or bytes of the variable dobj by characters or bytes of the data object new. Here, position-based and pattern-based replacement are possible.
When the replacement is executed, an interim result without a length limit is implicitly generated and the interim result is transferred to the data object dobj. If the length of the interim result is longer than the length of dobj, the data is cut off 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 to the right with blanks or hexadecimal zeroes. Data objects of variable length are adjusted. If data is cut off to the right when the interim result is assigned, sy-subrc is set to 2.In the case of character string processing, the closing spaces are taken into account for data objects dobj of fixed length; they are not taken into account in the case of new.
System fields
sy-subrc | Meaning |
0 | The specified section or subsequence was replaced by the content of new and the result is available in full in dobj. |
2 | The specified section or subsequence was replaced in dobj by the contents of new and the result of the replacement was cut off to the right. |
4 | The subsequence in sub_string was not found in dobj in the pattern-based search. |
8 | The data objects sub_string and new contain double-byte characters that cannot be interpreted. |
- Prev
- Next >>