Skip to content

ABAP Keyword Documentation →  ABAP − Reference →  Processing External Data →  ABAP Database Access →  ABAP SQL →  ABAP SQL - Operands and Expressions →  ABAP SQL - SQL Expressions sql_exp →  sql_exp - sql_cast 

sql_exp - sql_cast, Conversion Rules

The following sections describe the conversion rules for cast expressions in ABAP SQL.

Data types that cannot be converted to each other are not specified. In these cases, casts are either not possible or only casts between type-friendly operands. If the source type and the target type are technically identical, the content is transferred without being converted.

Other versions: 7.31 | 7.40 | 7.54

Numeric Source Type

Source Type INT1, INT2, INT4, INT8, DEC, CURR, QUAN, DECFLOAT16, DDECFLOAT34

  • Numeric target type
The possible target types are INT1, INT2, INT4, INT8, DEC, CURR, QUAN, DECFLOAT16, DECFLOAT34, and FLTP.

  • The source value is converted to the internal representation for the target type.

  • If the value range is exceeded, an exception is raised that can be caught using CX_SY_OPEN_SQL_DB. In the case of the target types DEC, CURR, and QUAN, this applies to the integer digits and any surplus decimal places are cut off without rounding.

  • In the case of the target type FLTP, values that cannot be represented as binary floating point numbers are converted to the next adjacent number.

  • Character-like target type
The possible target types are CHAR and SSTRING.

  • The number value is converted to a character string in mathematical notation without decimal separators and is left-aligned.

  • The length of the target type must be enough for all potential values including the sign.

  • In the case of the source types DECFLOAT16 and DECFLOAT34, scientific notation is produced from a specific value.

Note

When the source type DEC is converted to a character-like target type, the database specifies whether non-relevant zeros are displayed before and after the decimal separator.

Source Type DF16_DEC, DF34_DEC

  • Numeric target type
The possible target types are INT1, INT2, INT4, INT8, DECFLOAT16, and DECFLOAT34.

  • The source value is converted to the internal representation for the target type.

  • If the value range is exceeded, an exception is raised that can be caught using CX_SY_OPEN_SQL_DB.

Character-Like Source Type

Source Types CHAR, SSTRING

  • Character-like target type
The possible target types are CHAR, SSTRING, NUMC, DATS, TIMS, CLNT, LANG, UNIT, and CUKY.

  • The character string is written to the target field as a left-aligned string including leading blanks. If the target type is too short, it is truncated on the right and if the target field is too long, it is padded on the right with blanks.

  • There is no special handling for the special target type for numeric text, NUMC, and for the date/time types DATS and TIMS. It is advisable to only convert valid values.

Source Type NUMC

  • Numeric target type
The possible target types are INT1, INT2, INT4, INT8, DEC, CURR, QUAN, DECFLOAT16, DECFLOAT34, and FLTP.

  • The validity of the content of the source field is not checked, which means that there can be decimal places.

  • The source field must contain a character string that can be interpreted as a number. If not, an exception is raised that can be caught using CX_SY_OPEN_SQL_DB.

  • If the value range in the integer digits is exceeded, an exception is raised that can be caught using CX_SY_OPEN_SQL_DB.

  • In the case of the target types DECFLOAT16 and DECFLOAT34, rounding takes place to the last significant place.

  • In the case of the target types, INT1, INT2, and INT4, any decimal places in the source field raise an exception. In the case of the target types INT8, DEC, CURR, and QUAN, surplus decimal places are cut off without rounding.

  • In the case of the target type FLTP, values that cannot be represented as binary floating point numbers are converted to the next adjacent number.

  • Character-like target type
The possible target types are CHAR, SSTRING, NUMC, CLNT, DATS, and TIMS.

  • The validity of the source field is not checked.

  • The character string is written to the target field as a left-aligned string including leading blanks. If the target type is too short, it is truncated on the right and if the target field is too long, it is padded on the right with blanks.

  • There is no special handling for the special target type for numeric text, NUMC, and for the date/time types DATS and TIMS. It is advisable to only convert valid values.

Source Types DATS, TIMS, and CLNT

  • Character-like target types
The possible target types are CHAR, SSTRING, and NUMC.

  • The validity of the source field is not checked.

  • The character string is written to the target field as a left-aligned string including leading blanks. If the target type is too short, it is truncated on the right and if the target field is too long, it is padded on the right with blanks.

  • There is no special handling for the special target type for numeric text, NUMC. It is advisable to only convert valid values.

  • Date/time fields as target type (not for CLNT)
The possible target type for DATS is DATN and the possible target for TIMS is TIMN.

  • The value of the character-like date field or time field is converted to the internal value of the date type or time type.

  • The character-like date field or time field must contain a valid date or a valid time or the initial value. If not, an exception of the class CX_SY_OPEN_SQL_DB is raised.

Source Types LANG, UNIT, and CUKY

  • Character-like target types
The possible target types are CHAR and SSTRING.

  • The character string is written to the target field as a left-aligned string including leading blanks. If the target type is too short, it is truncated on the right and if the target field is too long, it is padded on the right with blanks.