ABAP Keyword Documentation → ABAP − Reference → Processing Internal Data → Internal Tables → Processing Statements for Internal Tables → REPLACE IN TABLE itab
REPLACE IN TABLE - options
Other versions: 7.31 | 7.40 | 7.54
Syntax
... [{RESPECTING|IGNORING} CASE]
[REPLACEMENT COUNT rcnt]
{ {[REPLACEMENT LINE rlin]
[REPLACEMENT OFFSET roff]
[REPLACEMENT LENGTH rlen]}
| [RESULTS result_tab|result_wa] } ...
Effect
The addition REPLACEMENT LINE
returns the last row number in which the search
pattern was found using the statement REPLACE
IN TABLE in rlin
. The following can be specified for rlin
:
-
An existing variable that expects the data type
i
. -
An inline declaration
DATA(var)
. The declared variable has the data typei
.
If no replacement is made, rlin
retains its existing value or stays initial.
The remaining additions used for making replacements in individual table rows have the same
meaning as pattern-based replacements made using
REPLACE
in elementary character strings or byte strings.
When the RESULTS
addition is used, the row numbers of each occurrence in
the component LINE of the table row in question in result_tab
or the row number of the last occurrence are saved to result_wa
.
Example
This example performs the same replacement as the replacement range example. Here, the positions of the replaced occurrences are returned.
TYPES:
BEGIN OF result,
line TYPE i,
offset TYPE i,
length TYPE i,
END OF result,
result_tab TYPE TABLE OF result WITH EMPTY KEY.
TYPES:
BEGIN OF line,
col1 TYPE c LENGTH 5,
col2 TYPE c LENGTH 5,
END OF line,
itab TYPE STANDARD TABLE OF line WITH EMPTY KEY.
DATA(itab) = VALUE itab( FOR i = 1 UNTIL i > 5
( col1 = 'abcde' col2 = 'abcde' ) ).
REPLACE ALL OCCURRENCES OF `cd`
IN TABLE itab
FROM 2 OFFSET 5
TO 4 OFFSET 5
WITH 'XX'
RESULTS DATA(results).
cl_demo_output=>display( CORRESPONDING result_tab( results ) ).