Additional Blogs by SAP
cancel
Showing results for 
Search instead for 
Did you mean: 
johannes_gilbert
Employee
Employee
0 Kudos

Introduction

The following code snippet shows how to convert string encoding in ABAP using the functionalities of package SIXML (iXML Library: Parsing, DOM Representation, and XML Rendering).

Code Snippet(s)

DATA:
      lv_content_string TYPE string, "the source string
      lv_target_encoding TYPE string DEFAULT 'UTF-8',
      lr_ixml           TYPE REF TO if_ixml,
      lr_stream_factory TYPE REF TO if_ixml_stream_factory,
      lr_encoding       TYPE REF TO if_ixml_encoding,
      lr_resstream      TYPE REF TO if_ixml_ostream,
      lv_content_xstring TYPE xstring. "the result string as binary string
      
    CLEAR rv_content_xstring.
*   Instanciate iXML object.
    lr_ixml = cl_ixml=>create( ).
*   Instanciate a stream factory.
    lr_stream_factory = lr_ixml->create_stream_factory( ).
*   Setup target encoding information.
    lr_encoding = lr_ixml->create_encoding(
      character_set = lv_target_encoding
      byte_order = 0 ).
*   Create the stream specifying where to push the output.
    lr_resstream = lr_stream_factory->create_ostream_xstring( lv_content_xstring ).
*   Set the output encoding.
    CALL METHOD lr_resstream->set_encoding( lr_encoding ).
*   Transform the data encoding.
    CALL TRANSFORMATION id
      SOURCE XML lv_content_string
      RESULT XML lr_resstream.

Explanation

The functionalities of class CL_IXML are used to convert the string encoding via stream processing.

Availability

KeyValue
Software ComponentSAP_BASIS
1 Comment