‎2007 Feb 01 11:46 AM
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
‎2007 Feb 05 4:18 PM
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
‎2008 Jun 16 3:00 PM
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