1. WRITE
f TO g[+off][(len)].
2. WRITE f TO itab[+off][(len)] INDEX idx.
WRITE f TO g[+off][(len)].
Assigns the contents of the source field f to the target
field
g
as a new value.
In contrast to MOVE,
the format of the target field g is the same as when outputting
to a list with WRITE. The
field type C is always used, regardless of the actual
data type.
As with list output, the settings in the user's master record for decimal point
(period or comma) and date format are taken into account.
Other formatting
options are also possible with list output.
Instead of specifying a static source field
f, you can also specify a source field (name)
dynamically. In this case, the content of the field name
is interpreted as the source field name at runtime. The content of this named field is then formatted
accordingly.
You can identify the target field g
more precisely by specifying the offset and/or length in the form g+off(len).
Both the offset and the length specifications off and
len can also be dynamic.
In the WRITE name TO
g
variant, the
return code is set as follows:
SY-SUBRC
= 0:
Contents of name are valid, statement
executed.
SY-SUBRC = 4:
Contents
of name are invalid, statement could not be executed,
and contents of g remain unchanged.
In other cases, the return code is undefined.
WRITE ... TO with dynamic source field specification and dynamic offset and length specification for the target field:
DATA: NAME(5) VALUE 'FIELD',
FIELD(5) VALUE 'Harry',
DEST(18) VALUE 'Robert James Smith',
OFF TYPE
I,
LEN TYPE I.
OFF = 7.
LEN = 8.
WRITE (NAME) TO DEST+OFF(LEN).
The field DEST now contains the value "Robert Harry ith".
... option
Modifies the output format with the aid of special formatting options.
WRITE f TO itab[+off][(len)] INDEX idx.
Additions like variant 1.
This variant is not allowed in an ABAP Objects context. See WRITE TO not allowed with internal tables.
Like variant 1, except that output is to the idx-th line
of the internal table itab.
Any offset and/or length specifications
refer to the table line used for output.
The Return Code is set as follows:
Invalid index specifications, i.e. idx <= 0, result in a runtime error.
The runtime of WRITE ... TO corresponds with that of the WRITE statement. However, considerable extra runtime is required if you specify the source field dynamically.
Specifying the target field using offset and length increases the runtime slightly.
Non-Catchable Exceptions
Assigning Values Using WRITE TO