ABAP - Keyword Documentation →  ABAP - Reference →  Processing Internal Data →  Character String and Byte String Processing →  Statements for Character String and Byte String Processing → 

WRITE - TO

Quick Reference

Syntax

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

Effect

The statement WRITE TO prepares the content of a source either using

as a character string and assigns the formatted content to the character-like data object destination.

The source field can be specified either statically or dynamically:

If static, the field is specified directly as source. source is a general expression position with the restriction that no numeric literals, arithmetic expressions, or bit expressions can be specified directly.
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:
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.

The target field destination must be character-like and flat‎.

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

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.

Exceptions

Handleable Exceptions

CX_SY_WRITE_INVALID_STYLE

CX_SY_CONVERSION_NO_NUMBER

CX_SY_CONVERSION_OVERFLOW

Non-Handleable Exceptions



Continue
WRITE - Predefined Formats
WRITE - format_options
WRITE - Cutoff Behavior