REPLACE sub_string WITH

Short Reference

Syntax

REPLACE sub_string WITH new INTO dobj
        [IN {BYTE|CHARACTER} MODE]
        [LENGTH len].


Extras:

1. ... IN {BYTE|CHARACTER} MODE

2. ... LENGTH len

Effect

This statement searches through a byte string or character string dobj for the subsequence specified in sub_string and replaces the first byte or character string in dobj that matches sub_string with the contents of the data object new.

The memory areas of sub_string and new must not overlap, otherwise the result is undefined. If sub_string is an empty string, the point before the first character or byte of the search area is found and the content of new is inserted before the first character.

During character string processing, the closing blank is considered for data objects dobj, sub_string and new of type c, d, n or t.

System Fields

sy-subrc Meaning
0 The subsequence in sub_string was replaced in the target field dobj with the content of new.
4 The subsequence in sub_string could not be replaced in the target field dobj with the contents of new.

Note

This variant of the statement REPLACE will be replaced, beginning with Release 6.10, with a new variant.

Addition 1

... IN {BYTE|CHARACTER} MODE

Effect

The optional addition IN {BYTE|CHARACTER} MODE determines whether byte or character string processing will be executed. If the addition is not specified, character string processing is executed. Depending on the processing type, the data objects sub_string, new, and dobj must be byte or character type.

Addition 2

... LENGTH len

Effect

If the addition LENGTH is not specified, all the data objects involved are evaluated in their entire length. If the addition LENGTH is specified, only the first len bytes or characters of sub_string are used for the search. For len, a data object of the type i is expected.

If the length of the interim result is longer than the length of dobj, data objects of fixed length will be cut off to the right. 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 with hexadecimal 0. Data objects of variable length are adapted.

Example

After the replacements, text1 contains the complete content "I should know that you know", while text2 has the cut-off content "I should know that".

DATA:   text1      TYPE string       VALUE 'I know you know',
        text2(18)  TYPE c LENGTH 18  VALUE 'I know you know',
        sub_string TYPE string       VALUE 'know',
        new        TYPE string       VALUE 'should know that'.

REPLACE sub_string WITH new INTO text1.
REPLACE sub_string WITH new INTO text2.