Skip to content

ABAP Keyword Documentation →  ABAP - Reference →  Processing Internal Data →  Assignments 

Assignment and Conversion Rules

When assigning the value of a source object (source) 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 to the exact byte. For deep data objects, a reference is created in the destination object, the actual byte-like content of which 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 retain 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.
  • If the data objects are neither compatible nor convertible, then no assignment can take place. If the syntax check detects this situation, a syntax error is displayed; otherwise an exception is raised when the program is executed.
  • 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 contents of data objects are 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 some cases, for comparisons, different rules apply than the usual rules for assignments. In particular, exceptions that can be resolved for assignments, cannot be resolved for comparisons.

    • 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 during the assignment process.

    • 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 Meshes

    CONV - Conversion Operator

    System Classes for Converting Character Sets and Number Formats

    Conversions - Performance Note