OVERLAY statement syntax with example

In ABAP OVERLAY statement is used for overlaying the characters of string on another string. Overlayed string characters will be replaced by the other string characters according to the position.

Dont be confused, you will get more idea after seeing one examples.

Example 1

  • Take two strings ,
  • string1=ABCDEF
  • string2=12345
  • Command for OVERLAY is “OVERLAY string1 WITH string2.”
  • After this, string1 will becomes 12345F.
  • The first 5 characters of string1 have replaced by the string2.

Example 2

  • string1=A B C D E F
  • string2=12 3 4 5
  • After the command OVERLAY string1 WITH string2.
  • string1 will becomes 12B3C4D5
  • Each character is replaced with the characters of string2 as per the position.
  • In this example blank spaces of string1 also replaced.

If we need to replace only characters ( not blank spaces ),we need to used an additional parameter “ONLY str” with OVERLAY statement.

The complete syntax will be :
OVERLAY string1 WITH string2 [ONLY str].

overlay statement in sap abap