Show TOC

Overlaying Character FieldsLocate this document in the navigation structure

The OVERLAY statement overlays one string with another:

OVERLAY c1 WITH c2 [ONLY str].

This statement overlays all positions in field c1containing letters which occur in str with the contents of c2. c2remains unchanged. If you omit ONLY str, all positions of c1 containing spaces are overwritten.

If at least one character inc1was replaced, sy-subrc is set to 0. In all other cases, sy-subrc is set to 4. If c1 is longer than c2, it is overlaid only in the length of c2.

Tip

DATA: t(10) TYPE c VALUE 'a c e g i ',      string LIKE t,      over(10) TYPE c VALUE 'ABCDEFGHIJ',      str(2) TYPE c VALUE 'ai'.

string = t.WRITE string.WRITE / over.

OVERLAY string WITH over.WRITE / string.

string = t.OVERLAY string WITH over ONLY str.WRITE / string.

Output:

a c e g i

ABCDEFGHIJ

aBcDeFgHiJ

A c e g I