REPLACE f WITH g INTO h.
1. ...
LENGTH len
2. ...
IN BYTE MODE
3. ... IN CHARACTER MODE
Depending on whether byte or character string processing is carried out, the operands can only be byte-type or character-type (see Overview).
The syntax check performed in an ABAP Objects context is stricter than in other ABAP areas. See Only character-like fields in character string processing.
In some cases, the syntax rules that apply to Unicode programs are different than those for non-Unicode programs. You should no longer use the second variant in Unicode programs. For details on this, see Character String Processing.
The first occurrence of the contents of field f in field
h is replaced with the contents of field g.
All fields involved are always evaluated in their defined length, including C fields in which blanks at the end are normally ignored.
System values
Return Code indicates whether the search character string f
was found in h and could be replaced with g:
sy-subrc = 0
Character string could be replaced.
sy-subrc <> 0
Character string could not be replaced.
DATA field(10) TYPE C.
MOVE 'ABCB' TO field.
REPLACE 'B' WITH 'string' INTO field.
returns: field = 'AstringCB', SY-SUBRC = 0
The fields f and g
of the REPLACE statement must not overlap since the result is undefined then.
... LENGTH len
The search pattern
f is not searched for in field h in its defined field length but in the length len.
DATA: pattern(6) TYPE C VALUE 'ABC',
len TYPE
I,
repl_string(6) TYPE C VALUE '123456',
field(12) TYPE
C VALUE 'abcdeABCDE'.
REPLACE pattern WITH repl_string INTO field.
Does not change
field since 'ABC ' does not occur in 'abcdeABCDE '.
len = STRLEN( pattern ).
REPLACE pattern LENGTH len
WITH
repl_string
INTO field.
Changes field to 'abcde123456D'.
... IN BYTE MODE
If you use this addition, all fields must be of the type X or XSTRING.
... IN CHARACTER MODE
This addition is optional and corresponds to the default setting.
Replacing Field Contents