Friday, December 11, 2009

Overlaying Character Fields

Overlaying Character Fields

Is good to use if you want to fill the number for certain format.

e.g if the data contain value 65 and the format data should be 65000

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 in c1 was 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.
Example

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

No comments:

Post a Comment