REPLACE SECTION [OFFSET off] [LENGTH len] OF dobj WITH new
[IN {BYTE|CHARACTER} MODE].
When replacing position-based, the section in dobj is
replaced starting at the offset specified in off for the
length specified in <>ABlen> with the content of data object new.
For off and len,
data objects of data type i are expected. You must specify
at least one of the additions OFFSET or
LENGTH. If you specify an offset but no length, the content of data object
dobj is replaced starting at the offset off
to the end. If you specify a length but no offset, the offest 0 is implicitly used. The values of
off and len must be greater than or equal to
0 and the section specified by off and
len must lie within the length of dobj.
... IN {BYTE|CHARACTER} MODE
The optional IN {BYTE|CHARACTER} MODE addition determines whether
byte-type or character- type processing is carried out. If the
addition is not specified, character string processing is carried out. Depending on the processing type,
dobj and new have to be byte-type or character- type.
Use the FIND statement to determine offset and length of the first word "know" in the data objects text1 and text2 and to replace this section position-based in text1 and text2 by "should know that". After the first REPLACE statement, text1 contains the complete content "I should know that you know" and sy-subrc contains 0. After the second REPLACE statement, text2 contains the truncated content "I should know that" and sy-subrc contains 2.
DATA: text1 TYPE string,
text2 TYPE c LENGTH 18,
off TYPE i,
len TYPE i.
text1 = text2 = 'I know you know'.
FIND 'know' IN text1 MATCH OFFSET off
MATCH LENGTH len.
REPLACE SECTION OFFSET off LENGTH len OF:
text1 WITH 'should know that',
text2 WITH 'should know that'.
Catchable Exceptions
CX_SY_RANGE_OUT_OF_BOUNDS