SAP NATIVE SQL TYPE MAPPING



Get Example source ABAP code based on a different SAP table
  



ABAP_NATIVE_SQL - Mapping of ABAP Types
In Native SQL, data can be transferred from the database to ABAP data objects in reads and vice versa in writes.
In ADBC, ABAP data objects are bound using data references.
ABAP data objects are specified as host variables after EXEC SQL.
In assignments between ABAP data objects and fields in database tables, the ABAP data objects are bound to the database fields using the Native SQL interface. ABAP data objects should usually only be bound to suitable database fields. The following tables show which elementary ABAP types match which HANA types, using the SAP HANA database as an example. There are similar assignments for other database systems.
Numeric Types ABAP TypeHANA Type
bSMALLINT
sSMALLINT
iINTEGER
int8BIGINT
p, length leng with dec decimal places DECIMAL, length 2len-1 with dec decimal places
decfloat16SMALLDECIMAL, length 16
decfloat34DECIMAL, length 34
fDOUBLE
Character-Like Types ABAP TypeHANA Type
c, length lenNVARCHAR, length len
stringNCLOB
n, length lenNVARCHAR, length len
Byte-Like Types ABAP TypeHANA Type
x, length lenVARBINARY, length len
xstringBLOB
Date Types, Time Types, and Time Stamp Types ABAP TypeHANA Type
dDATE; lbr NVARCHAR, length 8
tTIME; lbr NVARCHAR, length 6
utclongTIMESTAMP
If the data types match, the content can be passed unchanged without being checked. In all other cases, conversions are necessary. These conversions and the necessary checks are performed by the Native SQL interface. The conversions take place in the platform-dependent part (Client Library) of the Native SQL interface, and the following problems can occur:
Unexpected conversion results
Cutting off or padding of values for character-like and byte-like types
Conversion rules different to those in ABAP
SQL errors that raise exceptions
For this reason, conversions in the Native SQL interface should be avoided if possible. This is particularly relevant for the ABAP types n, d, and t and decimal floating point numbers.



Latest notes:

Unlike Native SQL, AB_SQL respects the column types of database tables and views defined in the ABAP Dictionary. These are based on the built-in data types of the ABAP Dictionary, which can all be mapped to a built-in ABAP type. Therefore, the AB-SQL interface can also execute platform-independent conversions between incompatible data types if they correspond to the conversion ru les in ABAP. For example, see the assignment rules for reads.
ABAP_HINT_END



Example ABAP Coding

The example shows that if the data of a column with type NUMC is assigned in Native SQL to a host variable with the ABAP type n that is too short, it is truncated on the right. The rule that is applied in AB_SQL , however, passes the data right-aligned and truncated on the left.
ABEXA 01143
The result in an SAP HANA database is: ABAP SQL: 00123

Native SQL 00000
ABAP_EXAMPLE_END



Example ABAP Coding

The example shows that if a host variable with ABAP type n that is too long is assigned to a column with type NUMC in Native SQL, an exception is raised. The conversion rule that is applied in AB_SQL , however, passes the data right-aligned and truncated on the left.
ABEXA 01144
The result in an SAP HANA database is: ABAP SQL:
2222233333

Native SQL
An SQL error has occurred: inserted value too large for column
ABAP_EXAMPLE_END