SAP SQL TYPE CONV FUNC



Get Example source ABAP code based on a different SAP table
  


• BINTOHEX ABAP_OSQL_FUNC
• HEXTOBIN ABAP_OSQL_FUNC
• TO_CLOB ABAP_OSQL_FUNC
• TO_BLOB ABAP_OSQL_FUNC

ABAP_SQLFUNC - Type Conversion Functions

ABAP_SYNTAX
... BINTOHEX( sql_exp )
$| HEXTOBIN( sql_exp )
$| TO_CLOB( sql_exp )
$| TO_BLOB( sql_exp ) ...

ABAP_VARIANTS:
1A ... BINTOHEX( sql_exp )
1B ... HEXTOBIN( sql_exp )
2A ... TO_CLOB( sql_exp )
2B ... TO_BLOB( sql_exp )

What does it do?
Functions for conversions between data types in an AB-SQL statement.



Latest notes:

These SQL functions execute special conversions that cannot be handled in a general CAST expression.
NON_V5_HINTS
For all type conversion functions, the syntax check is performed in the corresponding strict mode.
ABAP_HINT_END

ABAP_VARIANT_1A ... BINTOHEX( sql_exp )

ABAP_VARIANT_1B ... HEXTOBIN( sql_exp )

What does it do?
The BINTOHEX and HEXTOBIN functions convert byte strings to character strings and vice versa. The argument sql_exp can be an SQL expression, where literals are only possible to a limited extend:
BINTOHEX takes a byte string and converts it to a character string that contains 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.
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 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 can contain only the hexadecimal characters 0 to 9 and A to F in 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 entire conversion function is the null value.



Latest notes:

NON_V5_HINTS
The functions HEXTOBIN and BINTOHEX enforce the ABAP_STRICT_768 strict mode from ABAP_RELEASE ABAP_768 / .
ABAP_HINT_END

ABAP_EXAMPLE_VX5
The ID column of the DDIC 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.
ABEXA 01289
ABAP_EXAMPLE_END

ABAP_VARIANT_2A ... TO_CLOB( sql_exp )

What does it do?
The TO_CLOB function converts the value of the operand sql_exp from a character string of fixed length of type CHAR or SSTRING to a CLOB of type STRING. The argument sql_exp can be a column, a literal, a host variable, a host constant, or an SQL expression. The data type of the argument must be CHAR or SSTRING. The result is a CLOB of type STRING.
If the argument has a null value, the result of the conversion function is the null value.



Latest notes:

After the conversion, streaming and locators can be used on the result and length restrictions can be avoided. For example, when using STRING_AGG in combination with TO_CLOB, it is possible to read data strings that are much greater than the strings that can be read with STRING_AGG alone.
When using streaming and locators in combination with the conversion function TO_CLOB , it is not allowed to use LOB interfaces and the addition CREATING.
NON_V5_HINTS
TO_CLOB enforces the ABAP_STRICT_779 strict mode from ABAP_RELEASE ABAP_779 / .
ABAP_HINT_END

ABAP_EXAMPLE_VX5
The SELECT-statement reads the value of column CHAR10 from the DDIC database table DEMO_DDIC_TYPES and converts it from type CHAR to a CLOB of type STRING. Then, a reader stream is created that reads the CLOB in chunks of two characters and returns a list of 2-digit numbers.
ABEXA 01439
ABAP_EXAMPLE_END

ABAP_VARIANT_2B ... TO_BLOB( sql_exp )
The TO_BLOB function converts the value of the operand sql_exp from a byte field of type RAW to a byte string (BLOB) of type RAWSTRING. The argument sql_exp can be a column, a literal, a host variable, a host constant, or an SQL expression. The data type of the argument must be RAW. The result is a BLOB of type RAWSTRING.
If the argument has a null value, the result of the entire conversion function is the null value.



Latest notes:

After the conversion, streaming and locators can be used on the result and possible length restrictions can be avoided.
When using streaming and locators in combination with the conversion function TO_BLOB , LOB interfaces and the addition CREATING cannot be used.
NON_V5_HINTS
TO_BLOB enforces the ABAP_STRICT_780 strict mode from ABAP_RELEASE ABAP_780 / .
ABAP_HINT_END

ABAP_EXAMPLE_VX5
A variable of the built-in ABAP type x , which maps to the ABAP Dictionary type RAWSTRING, is inserted into a database field, which requires type RAW, which maps to the ABAP type xstring, using the conversion function TO_BLOB.
ABEXA 01440
ABAP_EXAMPLE_END