ABAP - Keyword Documentation →  ABAP - Reference →  Processing External Data →  ABAP Database Accesses →  Open SQL →  Open SQL - Operands and Expressions →  Open SQL - Built-In Functions sql_func →  Open SQL - Special Functions →  Open SQL - Conversion Functions → 

sql_exp - Type Conversion Functions

Syntax

... BINTOHEX( expr )
  | HEXTOBIN( expr ) ...


Variants:

1a. ... BINTOHEX( expr )

1b. ... HEXTOBIN( expr )

Effect

Functions for conversions between data types in an Open SQL statement.

Notes

Variant 1a

... BINTOHEX( expr )

Variant 1b

... HEXTOBIN( expr )



Effect

The BINTOHEX and HEXTOBIN functions convert byte strings to character strings and the other way round. The argument expr can be an SQL expression, in particular an individual column, an SQL function, a host variable, or a host expression. Literals can only be used to a restricted extent.

If the argument has a null value, the result of the full conversion function is the null value.

Example

The ID column of the database table IWREFERENC contains 32-character character-like UUIDs in hexadecimal representation. The statement SELECT reads a UUID once directly and once as the result of the predefined function HEXTOBIN. The function produces the same result as a conversion using the class CL_SYSTEM_UUID. Of course, in ABAP the simple assignment uuid16 = wa-uuid32 would be possible instead of the method call, since the conversion of c to x has the same result.

SELECT SINGLE id AS uuid32, hextobin( id ) AS uuid16
       FROM iwreferenc
       WHERE tcode = 'SE38'
       INTO @DATA(wa).

IF sy-subrc = 0.
  DATA uuid16 LIKE wa-uuid16.
  cl_system_uuid=>convert_uuid_c32_static(
    EXPORTING
      uuid          =     wa-uuid32
    IMPORTING
      uuid_x16      =     uuid16 ).
  ASSERT wa-uuid16 = uuid16.
ENDIF.