WRITE - TO

Short Reference

Syntax

WRITE {source|(source_name)} TO destination
                            [int_format_options].

Effect:

This statement assigns the formatted content of the data object source, or the formatted content of the data object whose name is contained in source_name, to the data object destination. The data objects source_name and destination must be character type and flat. source_name can contain the name of the data object to be assigned in upper or lower case. If the data object specified in source_name does not exist, the assignment is not executed, and sy-subrc is set to 4.

The statement WRITE TO has the same effect as the statement WRITE for lists. This statement formats the content of source or the source field specified in source_name as described in the field. It does not, however, store the result in an output area of a list in the list buffer, but instead stores it in a variable. The output length is determined by the length of the variable.

The same additions int_format_options can be specified for formatting the content as in the statement WRITE for lists, except for NO-GAP and UNDER.

System fields

sy-subrc Meaning
0 The data object specified in source_name was found and the assignment was executed.
4 The data object specified in source_name was not found and the assignment was not executed.

For the static specification of source, sy-subrc is not set.

Notes:

If destination is specified as an untyped field symbol or an untyped formal parameter, and is not flat and character-type when the statement is executed, this leads to an untreatable exception in a Unicode program. In In non-Unicode programs, this only leads to an exception for deep types. Flat types are handled as character-type data types.

Example:

After the assignment, the variables date_short and date_long receive the current date in the order specified in the user master record. The variable date_long also contains the defined separators, as the output length is sufficiently long. The content of the variable date_mask is formatted according to the formatting addition DD/MM/YY.

DATA: date_short TYPE c LENGTH 8,
      date_long  TYPE c LENGTH 10,
      date_mask  TYPE c LENGTH 8.

WRITE sy-datum TO: date_short,
                   date_long,
                   date_mask DD/MM/YY.

Exceptions

Non-Catchable Exceptions