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_func →  ABAP SQL - Built-In Functions sql_func →  ABAP SQL - Special Functions →  ABAP SQL - Conversion Functions 

sql_exp - Type Conversion Functions

Other versions: 7.31 | 7.40 | 7.54


... BINTOHEX( sql_exp )
  | HEXTOBIN( sql_exp ) ...


1a. ... BINTOHEX( sql_exp )

1b. ... HEXTOBIN( sql_exp )


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


  • These SQL functions execute special conversions that cannot be handled in a general CAST expression.

Variant 1a

... BINTOHEX( sql_exp )

Variant 1b

... HEXTOBIN( sql_exp )


The BINTOHEX and HEXTOBIN functions convert byte strings to character strings and the other way round. The argument sql_exp can be an SQL expression. Here, literals can be used subject to restrictions:

  • BINTOHEX takes a byte string and converts it to a character string containing the half bytes of the value of sql_exp, 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 the value of sql_exp. Since the argument has the type RAW, a single literal cannot be specified for this function. However, literals can occur as arguments of host expressions of result type x.
  • HEXTOBIN converts a character string to a byte string whose half bytes are determined from the hexadecimal characters of the value of sql_exp. Any leading blanks are removed before the conversion from the value of sql_exp 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 the value of sql_exp. The number of characters in the argument 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. Character-like literals can be specified. If literals, host variables, or host expressions determine the argument directly, and not as part of a larger SQL expression, they cannot contain any leading blanks.

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


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 built-in 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. 
      uuid          =     wa-uuid32 
      uuid_x16      =     uuid16 ). 
  ASSERT wa-uuid16 = uuid16.