If dynamic, the field is specified as the content of a parenthesized flat character-like data object
source_name, which must contain the name of the data object in question (non-case-sensitive).
If the data object specified in source_name does not exist, no assignment
takes place and sy-subrc is set to 4. When evaluating source_name,
the same applies as to a dynamically specified
(name) in the statement ASSIGN. The following can be specified for source_name:
Literal or constants
If the data object source_name is specified
as a text field literal or as a constant, it can be evaluated statically and the specified data object is identified as the used object.
Variable
If the data object source_name is specified as a variable, it is specified only dynamically and the content is not evaluated statically.
When the statement is executed, name is not evaluated until runtime (in both cases).
Only the data types grouped together under the simple generic type can be used as source fields.
All flat data types; flat
structures are handled like a data object of type c and can only contain any character-like components.
The target field destination must be character-like and flat.
If the length of the target field destination is less than the length of the data object format either
predefined or specified using format_options, the output (when formatted and assigned) is shortened in accordance with a type-specific cutoff behavior
If the available length exceeds the length required for formatting, the system places the result in
the target field based on the predefined or self-defined alignment and fills the non-required space with blanks.
System Fields
sy-subrc
Meaning
0
The data object specified in source_name was found and the assignment was performed.
4
The data object specified in source_name could not be found and the assignment was not performed.
If the static source is specified, sy-subrc is not set.
Notes
Although the statement WRITE TO does not send any data to an output medium, the system may execute a
conversion routine.
The statement WRITE TO is primarily designed for formatting data for output
purposes but not for further internal processing. For example, a field can no longer be handled as a numeric data object if the decimal separator is displayed as a comma.
No numeric literals can be specified between WRITE and TO.
This is because, in this case, the statement cannot be distinguished from a WRITE statement with a specified position.
It is possible to use string templates as source fields for the statement WRITE
TO, but this is not usually recommended since both WRITE TO and string
templates are used to format data and only a single method should be used. It is best to use string templates only.
Example
After the assignment, the variables date_short and date_long
contain the current local date in the order specified in the user master record. The variable
date_long contains the separators defined there. The variable date_short
does not contain any separators since their length is not sufficient. The content of the variable
date_mask is formatted according to the formatting addition DD/MM/YY, for which their length is sufficient.
DATA: date_long TYPE c LENGTH 10, date_short TYPE c LENGTH 8,
date_mask TYPE c LENGTH 8.
WRITE sy-datlo TO: date_short,
date_long,
date_mask DD/MM/YY.