Assigning Values with Offset Specifications

You can specify offset and length for elementary data objects in any ABAP statement (see Specifying Offset Values fo Data Objects). In this case, the syntax of the MOVE statement is as follows:

Syntax

MOVE <f1>[+<o1>][(<l1>)] TO <f2>[+<o2>][(<l2>)].

The syntax of the assignment operator is as follows:

Syntax

<f2>[+<o2>][(<l2>)] = <f1>[+<o1>][(<l1>)].

The contents of the section of field <f1>, which begins at the position <o1>+1 and has a length of <l1>, are assigned to field <f2> where they overwrite the section which begins at the position <o2>+1 and has a length of <l2>.

In the MOVE statement, all offset and length specifications can be variables. This also applies to statements with the assignment operator, as long as these can also be written as MOVE statements. In statements where no field name is specified after the assignment operator, (for example, in mathematical expressions), all offset and length specifications must be unsigned number literals. For further information, see Numeric Operations).

SAP recommends that you assign values with offset and length specifications only between non-numeric fields. With numeric fields, the results can be meaningless.

DATA: F1(8) VALUE 'ABCDEFGH',
F2(20).

F2+6(5) = F1+3(5).

In this example, the assignment operator functions as follows:

DATA: F1(8) VALUE 'ABCDEFGH',
F2(8).

DATA: O TYPE I VALUE 2,
L TYPE I VALUE 4.

MOVE F1 TO F2.      WRITE F2.
MOVE F1+O(L) TO F2.      WRITE / F2.
MOVE F1 TO F2+O(L). WRITE / F2.

CLEAR F2.
MOVE F1 TO F2+O(L). WRITE / F2.
MOVE F1+O(L) TO F2+O(L). WRITE / F2.

This produces the following output:

ABCDEFGH

CDEF

CDABCD

  ABCD

  CDEF

First, the contents of F1 are assigned to F2 without offset specifications. Then, the same happens for F1 with offset and length specification. The next three MOVE statements overwrite the contents of F2 with offset 2. Note that F2 is filled with spaces on the right, in accordance with the rule listed in Source Type Character.