ABAP Keyword Documentation → ABAP − Reference → Processing Internal Data → Assignments
Assignment and Conversion Rules
When the value of a source object (source
) is assigned to a destination object (destination
), three cases can be distinguished with respect to the data type:
source
and destination
are
compatible, which means that all
technical type attributes
match. The content is copied from source
to destination
without being converted. For flat data objects and related character-like or byte-like structural areas, a copy of the source object is created down to the exact byte. In the case of
deep data objects, a reference
is created in the destination object and the actual byte-like content of the reference cannot be seen externally. When entire structures are assigned, the response in terms of
alignment gaps is undefined.
The binary content of an alignment gap in the destination structure can either be copied from the source structure or keep the original value.
source
and destination
are not compatible, but can be
converted. The content
of source
is converted in accordance with the conversion rules and then copied
to destination
. Two data types are convertible if a conversion rule exists
for them. An exception is raised if the content of source
cannot be handled
in accordance with the conversion rules. After an exception, the content of destination
is determined by the category of the data type. An assignment that requires a conversion is always slower than an assignment without conversion.
The following sections describe the conversion rules. Conversion rules exist for:
The special assignment rules for reference variables are described in a separate section.
The conversion rules explained here generally apply to all assignments and all statements in which the content of data objects is changed. Exceptions to these rules are explained for each individual statement.
The conversion operator
CONV
can be
used in many operand positions to perform a conversion of a source value to an explicitly specified target data type in accordance with the rules explained here.
System classes are provided for special conversions of character sets and numeric formats.
Other versions: 7.31 | 7.40 | 7.54
Notes
- In the operand positions of many statements, assignments take place internally according to the assignment rules. If exceptions occur during an assignment, whether they can be handled or not depends on the operand and the operand position. The following are some examples:
- If functional method calls are used in operand positions, exceptions that can be handled when data objects are used directly cannot be handled and lead directly to runtime errors.
- In comparisons, some different rules apply than in assignments. Exceptions that are handleable in assignments are either handled implicitly or produce runtime errors and cannot be handled explicitly in comparisons.
- Using expressions in operand positions can make unhandleable exceptions handleable in some cases.
- The lossless operator
EXACT
can be used to perform checks before the conversion is carried out. These ensure that only applicable values are assigned and that no values are lost in assignments.
- Checks generally are not made on assignments between compatible data objects. If a data object already contains an invalid value, for example an invalid date or time in a date or time field, then this value is passed just like a valid value if the assignment is being made to a compatible data object.
Programming Guideline
Avoid unexpected conversion results
Continue
Conversion Rules for Elementary Data Objects
Conversion Rules for Structures
Conversion Rules for Internal Tables
Conversion Rules for Enumerated Types
System Classes for Converting Character Sets and Number Formats