Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Simple XML Transformation: Dump on converting several elements into xstring

Former Member
0 Likes
1,268

Hi all,

I'm having troubles to use a simple transformation that creates a byte-string (xstring) as result. It is necessary for me to use a byte-string to have xml in UTF-8 format, because I need to transport data in file format between unicode and non-unicode systems.

I even tried to do things as simple as possible and took the SAP Example for simple transformations and just modified the result type...


* The code of the simple transformation
<?sap.transform simple?>
<tt:transform xmlns:tt="http://www.sap.com/transformation-templates" template="temp1" version="0.1">
  <tt:root name="PARA1"/>
  <tt:root name="PARA2"/>
  <tt:template name="temp1">
    <X1>
      <tt:value ref="PARA1"/>
    </X1>
    <X2>
      <tt:value ref="PARA2"/>
    </X2>
  </tt:template>
</tt:transform>

* Simple Transformation with xstring result
DATA xml_string TYPE xstring.
DATA field1(10) TYPE c VALUE 'Field1'.
DATA field2(10) TYPE c VALUE 'Field2'.

CALL TRANSFORMATION zst_demo
  SOURCE para1 = field1
         para2 = field2
  RESULT XML xml_string.

DATA result1 LIKE field1.
DATA result2 LIKE field2.

CALL TRANSFORMATION zst_demo
  SOURCE XML xml_string
  RESULT para1 = result1
         para2 = result2.

When executing the code and using a string as result everything works fine, but when using a xstring I get a dump considering "ST_INVALID_XML" with action "OpenElement". Converting only one data element works fine with an xstring, but when trying to convert 2 parameters I get that dump.

Any hints or another post with information on how to solve this?

Kind regards, Karsten

2 REPLIES 2
Read only

Former Member
0 Likes
738

Try this,


data: g_ixml type ref to if_ixml,
        g_stream_factory type ref to if_ixml_stream_factory,
        g_encoding type ref to if_ixml_encoding,
        ostream type ref to if_ixml_ostream.

DATA xml_string TYPE xstring.
DATA field1(10) TYPE c VALUE 'Field1'.
DATA field2(10) TYPE c VALUE 'Field2'.
constants: encoding type string value `utf-8`.

g_ixml = cl_ixml=>create( ).
g_stream_factory = g_ixml->create_stream_factory( ).
g_encoding = g_ixml->create_encoding( character_set = encoding
                                                           byte_order = 0 ).

ostream = g_stream_factory->create_ostream_xstring( string = xml_string ).
ostream->set_encoding( encoding = g_encoding ).

CALL TRANSFORMATION zst_demo
  SOURCE para1 = field1
                para2 = field2
  RESULT XML ostream.

This should work and you will have the xstring result in xml_string.

Suman

Read only

0 Likes
738

Hello Sumansen,

do you know how to change in transformation 'ID' encoding from 'utf-16' to 'utf-8' and how can I see this transformation code in general?

Thanks a lot.

Irina