Code: Alles auswählen.
DATA: length TYPE i,
buffer TYPE xstring,
data TYPE REF TO data,
view TYPE REF TO cl_abap_view_offlen,
conv_out TYPE REF TO cl_abap_conv_out_ce,
conv_in TYPE REF TO cl_abap_conv_in_ce,
exc TYPE REF TO cx_root.
FIELD-SYMBOLS: <xlike> TYPE x,
<clike> TYPE c.
TRY.
view = cl_abap_view_offlen=>create_legacy_view( value ).
CATCH cx_parameter_invalid_type.
ENDTRY.
conv_in = cl_abap_conv_in_ce=>create( encoding = fr_codepage
endian = endian
replacement = replacement
ignore_cerr = ignore_cerr ).
IF view IS BOUND.
ASSIGN value TO <xlike> CASTING.
conv_in->convert_struc( EXPORTING input = <xlike> view = view IMPORTING data = value ).
ELSE.
length = STRLEN( value ).
CREATE DATA data TYPE c LENGTH length.
ASSIGN data->* TO <clike>.
<clike> = value.
ASSIGN <clike> TO <xlike> CASTING.
conv_in->convert( EXPORTING input = <xlike> IMPORTING data = value ).
ENDIF.
Code: Alles auswählen.
method translate_codepage.
data: length type i,
buffer type xstring,
data type ref to data,
view type ref to cl_abap_view_offlen,
conv_out type ref to cl_abap_conv_out_ce,
conv_in type ref to cl_abap_conv_in_ce,
exc type ref to cx_root.
field-symbols: <xlike> type x,
<clike> type c.
try.
try.
view = cl_abap_view_offlen=>create_legacy_view( value ).
catch cx_parameter_invalid_type.
endtry.
if fr_codepage = '1100'.
conv_out = cl_abap_conv_out_ce=>create( encoding = to_codepage
endian = endian
replacement = replacement
ignore_cerr = ignore_cerr ).
conv_out->write( data = value view = view ).
buffer = conv_out->get_buffer( ).
length = xstrlen( buffer ).
create data data type x length length.
assign data->* to <xlike> casting.
<xlike> = buffer.
assign <xlike> to <clike> casting.
string_to_struc( exporting iv_string = <clike> importing es_struc = value ).
elseif to_codepage = '1100'.
conv_in = cl_abap_conv_in_ce=>create( encoding = fr_codepage
endian = endian
replacement = replacement
ignore_cerr = ignore_cerr ).
if view is bound.
assign value to <xlike> casting.
conv_in->convert_struc( exporting input = <xlike> view = view importing data = value ).
else.
length = strlen( value ).
create data data type c length length.
assign data->* to <clike>.
<clike> = value.
assign <clike> to <xlike> casting.
conv_in->convert( exporting input = <xlike> importing data = value ).
endif.
endif.
catch cx_root into exc.
err_msg = exc->get_text( ).
clear value.
exit.
endtry.
endmethod.
Code: Alles auswählen.
DATA: cp_fr TYPE abap_encod,
cp_to TYPE abap_encod.
DATA: BEGIN OF text_old,
word1 TYPE c LENGTH 4 VALUE 'AAAA',
word2 TYPE c LENGTH 4 VALUE 'BBBB',
word3 TYPE c LENGTH 4 VALUE 'CCCC',
word4 TYPE c LENGTH 4 VALUE 'DDDD',
END OF text_old,
test_string_old TYPE string VALUE 'AAAABBBBCCCCDDDD',
text_new LIKE text_old,
test_string_new TYPE string.
cp_fr = '0500'.
cp_to = '1100'.
text_new = text_old.
test_string_new = test_string_old.
TRANSLATE test_string_old FROM CODE PAGE cp_fr TO CODE PAGE cp_to.
TRANSLATE text_old FROM CODE PAGE cp_fr TO CODE PAGE cp_to.
zecl_conv_utilities=>translate_codepage(
EXPORTING
fr_codepage = cp_fr
to_codepage = cp_to
* ignore_cerr = abap_false
IMPORTING
err_msg = error
CHANGING
value = test_string_new
).
zecl_conv_utilities=>translate_codepage(
EXPORTING
fr_codepage = cp_fr
to_codepage = cp_to
* ignore_cerr = abap_false
IMPORTING
err_msg = error
CHANGING
value = text_new
).