ABAP Keyword Documentation → ABAP - Reference → Processing Internal Data → Character String and Byte String Processing → Statements for Character String and Byte String Processing
WRITE - TO
Other versions: 7.31 | 7.40 | 7.54
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
- predefined formats or
-
explicit formatting options
format_options
as a character string and assigns the formatted content to the character-like data object destination
.
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. You can specify the data object source
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).
-
If the length of the target field
destination
is less than the length of the data object format either predefined or specified usingformat_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.
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
-
If
destination
is specified as an untyped field symbol or an untyped formal parameter and is not flat and character-like when the statement is executed, this results in an exception (that cannot be handled) in Unicode programs. In non-Unicode programs, an exception only occurs if deep types are used, while flat types are handled like character-like types. -
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. -
Use of the
WRITE TO
statement can be replaced in most cases by embedded expressions in string templates of string expressions.
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
-
Cause:Incorrect output format for decimal floating point numbers with the
STYLE
addition.
Runtime Error:WRITE_INVALID_STYLE
CX_SY_CONVERSION_NO_NUMBER
-
Cause:Invalid format of the source field in the output of a decimal floating point number.
Runtime Error:CONVT_NO_NUMBER
CX_SY_CONVERSION_OVERFLOW
-
Cause: Target field is too short to display a decimal floating point number.
Runtime Error:CONVT_OVERFLOW
Non-Catchable Exceptions
-
Cause: Negative length specification for offset/length specification.
Runtime Error:WRITE_TO_LENGTH_NEGATIVE
-
Cause: Negative offset specification for offset/length specification.
Runtime Error:WRITE_TO_OFFSET_NEGATIVE
-
Cause: Offset specification for offset/length specification is larger than the field length.
Runtime Error:WRITE_TO_OFFSET_TOOLARGE
-
Cause:
CURRENCY
parameter inWRITE
does not have typec
Runtime Error:WRITE_CURRENCY_ILLEGAL_TYPE
-
Cause: Rounding parameter less than -14
Runtime Error:WRITE_ROUND_TOO_SMALL
-
Cause:
UNIT
parameter inWRITE
does not have typec
Runtime Error:WRITE_UNIT_ILLEGAL_TYPE
-
Cause: Incomplete rules for a time zone when using the addition
TIME ZONE
Runtime Error:CONVERT_TSTMP_INCONSISTENT_TAB