Code: Alles auswählen.
TRANSLATE l_h_satz-lasart FROM CODE PAGE '0100' TO CODE PAGE '1110'.
TRANSLATE l_h_satz-laz FROM CODE PAGE '0100' TO CODE PAGE '1110'.
Code: Alles auswählen.
FUNCTION zda_unicode_translate.
*"----------------------------------------------------------------------
*"*"Lokale Schnittstelle:
*" IMPORTING
*" VALUE(I_IN_ENCODING) TYPE ABAP_ENCOD
*" VALUE(I_OUT_ENCODING) TYPE ABAP_ENCOD
*" VALUE(I_DATA_TYPE) TYPE ABAPTYPE DEFAULT 'C'
*" CHANGING
*" VALUE(C_DATA_TO_CONVERT)
*" EXCEPTIONS
*" PARAMETER_IS_MISSING
*" WRONG_CONVERT_METHOD
*"----------------------------------------------------------------------
*** Created: Christian Burkhardt - Bit-Creations - ***
FIELD-SYMBOLS: <x_intext> TYPE x.
DATA: l_convout TYPE REF TO cl_abap_conv_out_ce,
l_convin TYPE REF TO cl_abap_conv_in_ce,
slen TYPE i,
l_input_string TYPE string,
convxstring TYPE xstring,
l_doing TYPE i,
hlp_offset TYPE i,
hlp_out TYPE c,
hlp_str TYPE string.
DATA: ob_desc TYPE REF TO cl_abap_structdescr,
ls_compo TYPE abap_compdescr.
FIELD-SYMBOLS: <field> TYPE ANY,
<struc> TYPE ANY.
*** STARTING ***
IF i_in_encoding IS INITIAL OR i_out_encoding IS INITIAL.
MESSAGE s208(00) WITH 'ENCODING Parameter fehlt!' RAISING parameter_is_missing.
ENDIF.
* Typ ermitteln
PERFORM get_type USING c_data_to_convert CHANGING i_data_type.
IF i_data_type = 'C'.
DESCRIBE FIELD c_data_to_convert LENGTH l_doing IN CHARACTER MODE.
ELSEIF i_data_type = 'S'.
l_doing = STRLEN( c_data_to_convert ).
ELSEIF i_data_type = 'U'.
* Falls Struktur übergeben wird, dann in Teilfelder zerlegen und rekursiv Baustein aufrufen
* TRY.
ob_desc ?= cl_abap_typedescr=>describe_by_data( c_data_to_convert ).
* catch assign_casting_illegal_cast.
* RAISE casting_error.
* ENDTRY.
LOOP AT ob_desc->components INTO ls_compo WHERE type_kind <> 'X' AND
type_kind <> 'I' AND
type_kind <> 'P' AND
type_kind <> 'F'.
ASSIGN COMPONENT ls_compo-name OF STRUCTURE c_data_to_convert TO <field>.
IF sy-subrc = 0. "<field> IS ASSIGNED.
* Rekursiver Aufruf
CALL FUNCTION 'ZDA_UNICODE_TRANSLATE'
EXPORTING
i_in_encoding = i_in_encoding
i_out_encoding = i_out_encoding
CHANGING
c_data_to_convert = <field>.
UNASSIGN <field>.
ENDIF.
ENDLOOP.
RETURN.
ENDIF.
* convstring = c_data_to_convert.
* CLEAR c_data_to_convert.
DO l_doing TIMES.
hlp_offset = sy-index - 1.
l_input_string = c_data_to_convert+hlp_offset(1).
* Falls ein Leerzeichen gemoved wurde, ist das jetzt dummerweise verschwunden
IF l_input_string = space.
l_input_string = ' x'.
TRANSLATE l_input_string USING 'x '.
ENDIF.
TRY.
l_convout = cl_abap_conv_out_ce=>create(
encoding = i_in_encoding ).
l_convout->convert(
EXPORTING
data = l_input_string
IMPORTING
buffer = convxstring
len = slen ).
CATCH cx_root.
* Bei der Zeichenkonvertierung ist ein Fehler aufgetreten
* c_data_to_convert+hlp_offset(1) = l_input_string(1).
CONTINUE.
* MESSAGE l_msgstr TYPE 'S'.
ENDTRY.
TRY.
CALL METHOD cl_abap_conv_in_ce=>create
EXPORTING
encoding = i_out_encoding
input = convxstring
RECEIVING
conv = l_convin.
CLEAR hlp_out.
CALL METHOD l_convin->read
EXPORTING
n = 2
IMPORTING
data = hlp_out.
l_input_string = hlp_out.
CATCH cx_root.
* Bei der Zeichenkonvertierung ist ein Fehler aufgetreten
MESSAGE s208(00) WITH 'Konvertierung konnte nicht durchgeführt werden!' RAISING wrong_convert_method.
ENDTRY.
* Bei Strings können keine Offsets verändert werden wenn andere Codepages im Spiel sind
IF i_data_type <> 'S'.
TRY.
c_data_to_convert+hlp_offset(1) = l_input_string(1).
CATCH cx_sy_range_out_of_bounds.
ENDTRY.
ELSE.
CONCATENATE hlp_str hlp_out INTO hlp_str.
ENDIF.
ENDDO.
IF i_data_type = 'S'.
c_data_to_convert = hlp_str.
ENDIF.
ENDFUNCTION.
*** FORMS ***
FORM get_type USING feld CHANGING i_data_type.
DATA: otype TYPE REF TO cl_abap_typedescr,
ostruc TYPE REF TO cl_abap_structdescr,
otable TYPE REF TO cl_abap_tabledescr,
xcomp LIKE LINE OF ostruc->components.
*
otype = cl_abap_typedescr=>describe_by_data( feld ).
CASE otype->type_kind.
WHEN 'g'. " String
i_data_type = 'S'.
WHEN 'u'. " Struktur
i_data_type = 'U'.
WHEN OTHERS. " wahrscheins Char ;-)
i_data_type = 'C'.
ENDCASE.
* CASE otype->type_kind.
*endcase.
*cx_root
ENDFORM. "get_type
Code: Alles auswählen.
ASSIGN COMPONENT ls_compo-name OF STRUCTURE c_data_to_convert TO <field>.
IF <field> IS ASSIGNED.
Code: Alles auswählen.
ASSIGN COMPONENT ls_compo-name OF STRUCTURE c_data_to_convert TO <field>.
IF sy-subrc EQ 0.