[ABAP] xstring (Bytes) nach string (Text) wandeln

Variante 1 (cl_abap_conv_in_ce)

DATA: lv_xstr TYPE xstring VALUE '54657374737472696E672066C3BC7220646965204B6F6D7072657373696F6E206D697420475A49502E'.
DATA: lv_str TYPE string.
  
* xstring (binary) -> string (UTF-8)
DATA(o_conv_r) = cl_abap_conv_in_ce=>create( input = lv_xstr encoding = 'UTF-8' ).
o_conv_r->read( IMPORTING data = lv_str ).

WRITE: / lv_str.

Variante 2 (/ui2/cl_abap2json)

DATA: lv_xstr TYPE xstring VALUE '54657374737472696E672066C3BC7220646965204B6F6D7072657373696F6E206D697420475A49502E'.

* xstring -> string (UTF-8)
DATA(lv_str) = /ui2/cl_abap2json=>conv_xstring_to_string( lv_xstr ).

WRITE: / lv_str.

Variante 3 (cl_proxy_service)

DATA: lv_xstr TYPE xstring VALUE '54657374737472696E672066C3BC7220646965204B6F6D7072657373696F6E206D697420475A49502E'.

* xstring (binary) -> string (4110)
DATA(lv_str_res) = cl_proxy_service=>xstring2cstring( lv_xstr ).

WRITE: / lv_str_res.

Variante 4 (ICT_DISPATCH)

DATA: lv_xstr TYPE xstring VALUE '54657374737472696E672066C3BC7220646965204B6F6D7072657373696F6E206D697420475A49502E'.
DATA: lv_string TYPE string.

* xstring (binary) -> string
CALL 'ICT_DISPATCH' ID 'did'    FIELD 'append_xstring_to_string'
                    ID 'source' FIELD lv_xstr
                    ID 'dest'   FIELD lv_string.

WRITE: / lv_string.

[ABAP] string (Text) nach xstring (Bytes) wandeln

Variante 1 (cl_abap_conv_out_ce)

DATA: lv_str TYPE string VALUE 'Teststring.'.
DATA: lv_xstr TYPE xstring.

* string (UTF-8) -> xstring (binary)
DATA(o_conv_w) = cl_abap_conv_out_ce=>create( encoding = 'UTF-8' ).
o_conv_w->write( data = lv_str ).
lv_xstr = o_conv_w->get_buffer( ).

WRITE: / lv_xstr.

Variante 2 (SCMS_STRING_TO_XSTRING)

DATA: lv_str TYPE string VALUE 'Teststring.'.
DATA: lv_xstr TYPE xstring.
  
CALL FUNCTION 'SCMS_STRING_TO_XSTRING'
  EXPORTING
    text   = lv_str
  IMPORTING
    buffer = lv_xstr.

WRITE: / lv_xstr.

Variante 3 (cl_proxy_service)

DATA: lv_str TYPE string VALUE 'Teststring.'.
* string (4110 / UTF-8) -> xstring (binary)
DATA(lv_xstr_res) = cl_proxy_service=>cstring2xstring( lv_str ).
WRITE: / lv_xstr_res.

Variante 4 (cl_abap_codepage)

DATA: lv_str TYPE string VALUE 'Teststring.'.
* string -> xstring (binary) (UTF-8)
DATA(xstr) = cl_abap_codepage=>convert_to( source   = lv_str
                                           codepage = 'UTF-8' ).
WRITE: / xstr.

Variante 5 (cl_abap_message_digest)

DATA: lv_str TYPE string VALUE 'Teststring.'.
* string (4110 / UTF-8) -> xstring (binary)
DATA(lv_xstr) = cl_abap_message_digest=>string_to_xstring( lv_str ).

WRITE: / lv_xstr.

Variante 6 (cl_abap_hmac)

DATA: lv_str TYPE string VALUE 'Teststring.'.
* string (4110 / UTF-8) -> xstring (binary)
DATA(lv_xstr) = cl_abap_hmac=>string_to_xstring( lv_str ).

WRITE: / lv_xstr.

Variante 7 (cl_clb_tools)

DATA: lv_str TYPE string VALUE 'Teststring.'.
* string -> xstring (binary) (UTF-8)
DATA(lv_xstr) = cl_clb_tools=>string_to_xstring( lv_str ).

WRITE: / lv_xstr.