Ansicht
Dokumentation

ABENSQL_TYPE_CONV_FUNC - SQL TYPE CONV FUNC

ABENSQL_TYPE_CONV_FUNC - SQL TYPE CONV FUNC

rdisp/max_wprun_time - Maximum work process run time   RFUMSV00 - Advance Return for Tax on Sales/Purchases  
This documentation is copyright by SAP AG.
SAP E-Book

- Type Conversion Functions

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


Variants:

1a. ... BINTOHEX( sql_exp )

1b. ... HEXTOBIN( sql_exp )

2a. ... TO_CLOB( sql_exp )

2b. ... TO_BLOB( sql_exp )

Effect

Functions for conversions between data types in an statement.

Notes

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

Variant 1a

... BINTOHEX( sql_exp )


Variant 1b

... HEXTOBIN( sql_exp )


Effect

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.

Note

The functions HEXTOBIN and BINTOHEX enforce the strict mode from Release .

Example

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.

Variant 2a

... TO_CLOB( sql_exp )


Effect

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.

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.
  • TO_CLOB enforces the strict mode from Release .

Example

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.

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.

Notes

  • After the conversion, streaming and locators can be used on the result and possible length restrictions can be avoided.
  • TO_BLOB enforces the strict mode from Release .

Example

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.






BAL_S_LOG - Application Log: Log header data   BAL Application Log Documentation  
This documentation is copyright by SAP AG.

Length: 10679 Date: 20240425 Time: 171822     sap01-206 ( 158 ms )