Code: Alles auswählen.
CL_BCS_CONVERT=>STRING_TO_XSTRING( IV_CONVERT_CP = ' ' .... )
Code: Alles auswählen.
export p = iv_string to data buffer lv_xbuf.
import p = ev_xstring from data buffer lv_xbuf
in char-to-hex mode.
Folgende Benutzer bedankten sich beim Autor edwin für den Beitrag:
a-dead-trousers
Code: Alles auswählen.
DATA: lr_conv TYPE REF TO cl_abap_conv_out_ce,
h_string TYPE string,
h_xstring TYPE xstring.
h_string = 'A-!-"-§-$-%-&-/-(-)-=-?-`-€'.
CALL FUNCTION 'SCMS_STRING_TO_XSTRING'
EXPORTING
text = h_string
IMPORTING
buffer = h_xstring
EXCEPTIONS
failed = 1
OTHERS = 2.
WRITE :/ 'String: ', h_string.
WRITE :/ 'xstring mit SCMS_STRING_TO_XSTRING: ', h_xstring.
CLEAR h_xstring.
lr_conv = cl_abap_conv_out_ce=>create( ).
TRY.
CALL METHOD lr_conv->write
EXPORTING
data = h_string.
CATCH cx_sy_codepage_converter_init.
MESSAGE 'Fehler cx_sy_codepage_converter_init' TYPE 'I'.
CATCH cx_sy_conversion_codepage.
MESSAGE 'Fehler cx_sy_conversion_codepage' TYPE 'I'.
CATCH cx_parameter_invalid_type.
MESSAGE 'Fehler cx_parameter_invalid_type' TYPE 'I'.
CATCH cx_parameter_invalid_range.
MESSAGE 'Fehler cx_parameter_invalid_range' TYPE 'I'.
ENDTRY.
TRY.
CALL METHOD lr_conv->get_buffer
RECEIVING
buffer = h_xstring.
CATCH cx_root.
MESSAGE 'Fehler cx_root' TYPE 'I'.
ENDTRY.
WRITE :/ ' xstring mit cl_abap_conv_out_ce: ', h_xstring.
CLEAR h_xstring.
TRY.
CALL METHOD cl_bcs_convert=>string_to_xstring(
EXPORTING
* iv_add_bom = ''
* iv_codepage = ''
iv_convert_cp = ''
iv_string = h_string
RECEIVING
ev_xstring = h_xstring ).
CATCH cx_bcs.
MESSAGE 'Fehler cx_bcs' TYPE 'I'.
ENDTRY.
WRITE :/ ' xstring mit cl_bcs_convert: ', h_xstring.
Folgende Benutzer bedankten sich beim Autor Legxis für den Beitrag:
a-dead-trousers
Code: Alles auswählen.
class ZCL_BYTE_CONVERT definition public create public.
public section.
class-methods FROM_CSEQUENCE_TO_XSTRING
importing
!ID_CSEQUENCE type CSEQUENCE
returning
value(RD_XSTRING) type XSTRING .
class-methods FROM_XSEQUENCE_TO_CSTRING
importing
!ID_XSEQUENCE type XSEQUENCE
returning
value(RD_CSTRING) type STRING .
ENDCLASS.
CLASS ZCL_BYTE_CONVERT IMPLEMENTATION.
METHOD FROM_CSEQUENCE_TO_XSTRING.
DATA:
ld_offset TYPE i,
ld_increment TYPE i,
ld_length TYPE i,
ld_buffer TYPE c LENGTH 100.
FIELD-SYMBOLS:
<la_buffer> TYPE any.
CLEAR rd_xstring.
IF id_csequence IS INITIAL.
RETURN.
ENDIF.
ld_length = strlen( id_csequence ).
CLEAR ld_offset.
DESCRIBE FIELD ld_buffer LENGTH ld_increment IN CHARACTER MODE.
ASSIGN ld_buffer TO <la_buffer> CASTING TYPE x.
WHILE ld_length GE ( ld_offset + ld_increment ).
ld_buffer = id_csequence+ld_offset(ld_increment).
CONCATENATE rd_xstring <la_buffer> INTO rd_xstring IN BYTE MODE.
ADD ld_increment TO ld_offset.
ENDWHILE.
IF ld_length GT ( ld_offset ).
ld_buffer = id_csequence+ld_offset.
ld_length = strlen( id_csequence+ld_offset ).
ld_increment = ld_length * cl_abap_char_utilities=>charsize.
CONCATENATE rd_xstring <la_buffer>(ld_increment) INTO rd_xstring IN BYTE MODE.
ENDIF.
ENDMETHOD.
METHOD from_xsequence_to_cstring.
DATA:
ld_offset TYPE i,
ld_increment TYPE i,
ld_length TYPE i,
ld_buffer TYPE c LENGTH 100.
FIELD-SYMBOLS:
<la_buffer> TYPE any.
CLEAR rd_cstring.
IF id_xsequence IS INITIAL.
RETURN.
ENDIF.
ld_length = xstrlen( id_xsequence ).
CLEAR ld_offset.
DESCRIBE FIELD ld_buffer LENGTH ld_increment IN BYTE MODE.
ASSIGN ld_buffer TO <la_buffer> CASTING TYPE x.
WHILE ld_length GE ( ld_offset + ld_increment ).
<la_buffer> = id_xsequence+ld_offset(ld_increment).
CONCATENATE rd_cstring ld_buffer INTO rd_cstring RESPECTING BLANKS.
ADD ld_increment TO ld_offset.
ENDWHILE.
IF ld_length GT ld_offset.
<la_buffer> = id_xsequence+ld_offset.
ld_length = xstrlen( id_xsequence+ld_offset ).
ld_increment = ld_length DIV cl_abap_char_utilities=>charsize.
* Beim Umwandeln von SBC auf DBC kann die Byte-Länge ungerade sein und somit würde das letzte Zeichen abgeschnitten werden.
IF ld_length MOD cl_abap_char_utilities=>charsize NE 0.
ADD 1 TO ld_increment.
* Sonderbehandlung damit beim Umwandeln kein Null-Zeichen am String-Ende übrigbleibt.
<la_buffer>+ld_length(1) = '20'.
ENDIF.
CONCATENATE rd_cstring ld_buffer(ld_increment) INTO rd_cstring RESPECTING BLANKS.
ENDIF.
ENDMETHOD.
ENDCLASS.
Folgende Benutzer bedankten sich beim Autor a-dead-trousers für den Beitrag:
Legxis