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

WRITE - TO  Syntax Diagram

Short Reference

Syntax

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

Effect

The statement WRITE TO formats the content of source or of the source field specified in source_name using either

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

source is a general expression position with the restriction that no numeric literals, arithmetic expressions, or bit expressions can be specified directly.

All flat data types and the data types string and xstring are allowed for source; structures are treated as a data object of type c and must be character-like in Unicode systems. In a Unicode system, only the data types grouped together under the simple generic type can be used. The data object source can be specified using either a field symbol or a dereferenced data reference.

The data objects source_name and destination must be character-like and have a fixed length (flat data type).

source_name can contain the name of the data object to be assigned in uppercase or lowercase. 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 for the dynamic specification of (name) in the statement ASSIGN.

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

Catchable Exceptions

CX_SY_WRITE_INVALID_STYLE

CX_SY_CONVERSION_NO_NUMBER

CX_SY_CONVERSION_OVERFLOW

Non-Catchable Exceptions




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