ABAP Keyword Documentation → ABAP - Dictionary → ABAP CDS in ABAP Dictionary → ABAP CDS - Data Definitions → ABAP CDS - DDL for Data Definitions → ABAP CDS - DEFINE VIEW → ABAP CDS - SELECT → ABAP CDS - SELECT, Built-In Functions → ABAP CDS - Special Functions → ABAP CDS - Conversion Functions
ABAP CDS - Type Conversion Functions
7.31 | 7.40 | 7.54
... FLTP_TO_DEC( arg AS dtype ) ...
... BINTOHEX( arg ) ...
... HEXTOBIN( arg ) ...
Functions for conversions between data types in a CDS view.
- These functions execute special conversions that cannot be handled in a general CAST expression.
- If an argument has the null value, the result of the conversion function is also the null value.
... FLTP_TO_DEC( arg AS dtype )
- Using a data element with this type.
- Directly as a built-in data type in ABAP Dictionary.
The following table shows the syntax for specifying built-in data types:
|abap.dec(len,decimals)||DEC with length len and decimals decimal places|
|abap.curr(len,decimals)||CURR with length len and decimals decimal places|
|abap.quan(len,decimals)||QUAN with length len with decimals decimal places|
The value range of the data type dtype must cover the value range of the operand type. An exception occurs if the value range of the target data type is not sufficient. Any surplus decimal places are cut off without rounding.
- The conversion of type FLTP to a packed number using the function FLTP_TO_DEC is platform dependent and does not have to be reversible using a CAST.
- The general CAST is designed to be platform-independent, which means it does not permit conversions of type FLTP to other numeric data types.
- Since a literal with a prefixed sign is interpreted as an arithmetic expression, the argument arg of the function FLTP_TO_DEC cannot be a negative literal. Instead, the sign can usually be specified before the function.
- More specifically, the built-in conversion function FLTP_TO_DEC can be used to convert literals with a decimal point to a packed number.
The following CDS view applies the function FLTP_TO_DEC in the SELECT
list to columns of the database table DEMO_EXPRESSIONS. The program
SELECT to access the view. Note that there is no rounding.
define view demo_cds_fltp_to_dec
as select from
fltp_to_dec( fltp1 as abap.dec(10,0) ) as dec1_10_0,
fltp_to_dec( fltp1 as abap.dec(10,3) ) as dec1_10_3,
fltp_to_dec( fltp2 as abap.dec(10,0) ) as dec2_10_0,
fltp_to_dec( fltp2 as abap.dec(10,3) ) as dec2_10_3
... BINTOHEX( arg )
... HEXTOBIN( arg )
The functions BINTOHEX and HEXTOBIN convert byte strings to character strings and back:
- BINTOHEX takes a byte string and converts it to a character string containing the half bytes of arg, converted to the hexadecimal characters "0" to "9" and "A" to "F" (left justified). The valid argument type is RAW with a maximum length of 255. The result has the type CHAR with twice the length of arg. Only fields of data sources can be specified as arguments.
- HEXTOBIN converts a character string to a byte string whose half bytes are determined from the hexadecimal characters of arg. Any leading blanks are removed before the conversion from arg and all trailing blanks are then replaced by "0". The valid argument types are is CHAR or NUMC with a maximum length of 510. The result has the type RAW with half the length of arg. Only fields of data sources and literals can be specified as arguments. The total of all characters must be even and it can contain only the hexadecimal characters "0" to "9" and "A" to "F" (uppercase or lowercase) and leading and trailing blanks. Literals cannot contain any leading blanks.
The following CDS view applies the conversion functions for byte strings in the SELECT
list to columns of the database table DEMO_EXPRESSIONS. The program DEMO_CDS_SQL_FUNCTIONS_BYTE uses
SELECT to access the view.
define view demo_cds_sql_functions_byte
as select from
bintohex( raw1 ) as r_bintohex,
hextobin( char1 ) as r_hextobin