OVERLAY

Basic form

OVERLAY c1 WITH c2.

Addition:


... ONLY c3

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 fields allowed in string processing.

In some cases, the syntax rules that apply to Unicode programs are different than those for non-Unicode programs. See Character String Processing and Unicode.

Effect

The contents of the field c2 overlay the field c1 in all positions where c1 has the value SPACE; c2 itself remains unchanged.

The Return Code is set as follows:

SY-SUBRC = 0:
At least one character in c1 is overlaid by a character from c2.
SY-SUBRC = 4:
No character in c1 was overlaid by a character from c2.

Example

DATA: WORK(20) VALUE 'Th t h s ch ng d.',
      HELP(20) VALUE 'Grab  a   pattern'.
OVERLAY WORK WITH HELP.

WORK now contains 'That has changed.' and the system field SY-SUBRC is set to 0.

Note

If c1 is longer than c2, c1 is only overlaid by the length of c2. The result for overlapping fields c1 and c2 is undefined.

Addition

... ONLY c3

Effect

The contents of the field c2 overlay the contents of field c1 in all positions where c1 has one of the characters contained in c3. The contents of the fields c2 and c3 remain unchanged.



Example

Linking field selection templates:

DATA: one(16),
      two(16).
one = '----****++++....'.
two = '-*+.-*+.-*+.-*+.'.
OVERLAY one WITH two ONLY '.'.
OVERLAY one WITH two ONLY '.+'.
OVERLAY one WITH two ONLY '+*'.

Field one now contains '-----*+.-*+.-*+.'.

Note

Performance:

The runtime required for the OVERLAY statement in the example of the basic form is about 45 msn (standardized microseconds). To execute the addition ... ONLY c3, about 40 msn are needed.

Related

FIND, REPLACE, SEARCH, SHIFT, TRANSLATE

Additional help

Overlaying Strings