Code: Alles auswählen.
TYPES: BEGIN OF ergebnis_string,
string(400) TYPE c, "Inhalt
END OF ergebnis_string,
BEGIN OF initial_structur,
zahl(4),
anzhl TYPE p DECIMALS 2,
END OF initial_structur.
DATA: it_erg TYPE STANDARD TABLE OF ergebnis_string,
wa_erg LIKE LINE OF it_erg.
DATA: it_import TYPE initial_structur.
FIELD-SYMBOLS <gv_import> LIKE it_import.
it_import-zahl = '0100'.
it_import-anzhl = '1.00'.
ASSIGN wa_erg TO <gv_import> CASTING.
<gv_import> = it_import.
APPEND wa_erg TO it_erg.
Code: Alles auswählen.
30313030000000000000100C = 30 31 30 30 000000000000100C = "0" "1" "0" "0" zahl Chars in non-unicode
3000310030003000000000000000100C = 3000 3100 3000 3000 000000000000100C = "0" "1" "0" "0" zahl Chars in unicode
Code: Alles auswählen.
REPORT.
TYPES: BEGIN OF ergebnis_string,
string(400) TYPE c, "Inhalt
END OF ergebnis_string,
BEGIN OF initial_structur,
zahl(4),
anzhl TYPE p DECIMALS 2,
END OF initial_structur.
DATA: it_erg TYPE STANDARD TABLE OF ergebnis_string,
wa_erg LIKE LINE OF it_erg.
DATA: it_import TYPE initial_structur.
it_import-zahl = '0100'.
it_import-anzhl = '1.00'.
DATA: wa_ergx TYPE xstring.
DATA: go_conv_legacy TYPE REF TO cl_abap_conv_out_ce,
go_view_legacy TYPE REF TO cl_abap_view_offlen.
DATA: go_conv_unicode TYPE REF TO cl_abap_conv_out_ce,
go_view_unicode TYPE REF TO cl_abap_view_offlen.
*--------------------------------------------------------------------*
* Konvertierung normal
*--------------------------------------------------------------------*
go_conv_legacy = cl_abap_conv_out_ce=>create( ).
go_view_legacy = cl_abap_view_offlen=>create_legacy_view( it_import ).
go_conv_legacy->convert_struc( EXPORTING data = it_import
view = go_view_legacy
IMPORTING buffer = wa_ergx ).
WRITE:/ 'Non-Unicode', AT 40 wa_ergx.
*--------------------------------------------------------------------*
* Konvertierung nach Unicode aus non-unicode system heraus
*--------------------------------------------------------------------*
go_conv_unicode = cl_abap_conv_out_ce=>create( encoding = '4100'
endian = 'B' ).
go_view_unicode = cl_abap_view_offlen=>create_unicode16_view( it_import ).
go_conv_unicode->convert_struc( EXPORTING data = it_import
view = go_view_unicode
IMPORTING buffer = wa_ergx ).
WRITE:/ 'Unicode big endian', AT 40 wa_ergx.
*--------------------------------------------------------------------*
* Konvertierung nach Unicode aus non-unicode system heraus
*--------------------------------------------------------------------*
go_conv_unicode = cl_abap_conv_out_ce=>create( encoding = '4101' ).
go_view_unicode = cl_abap_view_offlen=>create_unicode16_view( it_import ).
go_conv_unicode->convert_struc( EXPORTING data = it_import
view = go_view_unicode
IMPORTING buffer = wa_ergx ).
WRITE:/ 'Unicode little endian', AT 40 wa_ergx.
Code: Alles auswählen.
Non-Unicode 30313030000000000000100C
Unicode big endian 0030003100300030000000000000100C
Unicode little endian 3000310030003000000000000000100C
Code: Alles auswählen.
DATA: l_convin TYPE REF TO cl_abap_conv_in_ce,
l_msgstr TYPE string,
lv_string TYPE string.
DATA: lo_cx_root TYPE REF TO cx_root.
TRY.
CALL METHOD cl_abap_conv_in_ce=>create
EXPORTING
encoding = 'UTF-8'
input = wa_ergx
RECEIVING
conv = l_convin.
CALL METHOD l_convin->read
IMPORTING
data = lv_string.
WRITE:/ 'Wert', AT 40 lv_string.
CATCH cx_root INTO lo_cx_root.
BREAK-POINT.
ENDTRY.