2011 Feb 01 11:13 AM
Hello,
I need your help.
I have create a transformation from ABAP Structure with table to XML.
It is an XSLT-Transformation.
The transformation works very well from ABAP to xml-file (first part of report)
But the other way (second part of report) from the xml-file to SAP and transform it to the same ABAP-Structure with tabel doesn´t work. Message: " No valid source context specified".
Can anyone help?
Thanks
dste
The structure: Z_S_test contains one field named events and is from tabletype z_tt_testdata.
Tybletype z_tt_testdata is standard table with structure z_s_testdata.
Structur z_s_testdata have two fields: e_short (short_d) and e_stext (stext).
the transformation looks like:
<xsl:transform
xmlns:xsl ="http://www.w3.org/1999/XSL/Transform"
xmlns:sap ="http://www.sap.com/sapxsl"
version="1.0">
<xsl:strip-space elements="*"></xsl:strip-space>
<xsl:output encoding="UTF-8" indent="yes" method="xml"></xsl:output>
<xsl:variable name="newline">
<xsl:text></xsl:text>
</xsl:variable>
<xsl:template match="EVENTO/EVENTS">
<xsl:element name="TestEvent">
<xsl:for-each select="ZCM_S_TESTDATA">
<xsl:element name="TestDaten">
<xsl:element name="Short">
<xsl:value-of select="E_SHORT"></xsl:value-of>
</xsl:element>
<xsl:element name="Longtext">
<xsl:value-of select="E_STEXT"></xsl:value-of>
</xsl:element>
</xsl:element>
</xsl:for-each>
</xsl:element>
</xsl:template>
</xsl:transform>
Edited by: DSE on Feb 1, 2011 12:14 PM
2011 Feb 01 11:20 AM
Why missing the second part of my Question?
Here again the code of the test-report.
REPORT zz_test.
TYPES t_table TYPE TABLE OF sdokcntasc.
FIELD-SYMBOLS: <xml> TYPE sdokcntasc.
DATA: xml_line TYPE sdokcntasc.
DATA xml_string TYPE string.
DATA: gs_evento TYPE zcm_s_test.
DATA: gs_eventdata TYPE zcm_s_testdata.
DATA: xslt_error TYPE REF TO cx_xslt_exception ,
xslt_message TYPE string .
DATA: gr_ixml TYPE REF TO if_ixml,
gr_stream_factory TYPE REF TO if_ixml_stream_factory,
gr_encoding TYPE REF TO if_ixml_encoding,
gr_resstream TYPE REF TO if_ixml_ostream.
DATA: gi_ixml TYPE REF TO if_ixml,
gi_stream_factory TYPE REF TO if_ixml_stream_factory,
gi_encoding TYPE REF TO if_ixml_encoding,
gi_parser TYPE REF TO if_ixml_parser,
gi_document TYPE REF TO if_ixml_document,
gi_resstream TYPE REF TO if_ixml_istream.
DATA: xml_table TYPE t_table.
DATA: gv_ressize TYPE i VALUE 0,
gv_s TYPE string.
CONSTANTS: encoding TYPE string VALUE 'utf-8'.
* First part: ABAP to XML
gs_eventdata-e_short = '1234567890'.
gs_eventdata-e_stext = 'Test1'.
APPEND gs_eventdata TO gs_evento-events.
gs_eventdata-e_short = '2345678901'.
gs_eventdata-e_stext = 'Test2'.
APPEND gs_eventdata TO gs_evento-events.
gs_eventdata-e_short = '3456789012'.
gs_eventdata-e_stext = 'Test3'.
APPEND gs_eventdata TO gs_evento-events.
gr_ixml = cl_ixml=>create( ).
gr_stream_factory = gr_ixml->create_stream_factory( ).
gr_encoding = gr_ixml->create_encoding( character_set = encoding byte_order = 0 ).
gr_resstream = gr_stream_factory->create_ostream_itable( table = xml_table ).
gr_resstream->set_encoding( encoding = gr_encoding ).
CALL TRANSFORMATION ('ZCM_XSLT_TEST_XML')
SOURCE evento = gs_evento
RESULT XML gr_resstream.
gv_ressize = gr_resstream->get_num_written_raw( ).
MOVE '\\sapxx1\tmp\test-xml.xml' TO gv_s.
OPEN DATASET gv_s FOR OUTPUT IN BINARY MODE.
LOOP AT xml_table ASSIGNING <xml>.
TRANSFER <xml> TO gv_s. " LENGTH pv_ressize.
ENDLOOP.
CLOSE DATASET gv_s.
*##########################################################################
* second part: XML to ABAP
REFRESH xml_table.
CLEAR gs_evento.
*OPEN DATASET gv_s FOR INPUT IN BINARY MODE.
OPEN DATASET gv_s FOR INPUT IN TEXT MODE ENCODING UTF-8.
DO.
READ DATASET gv_s INTO xml_line.
IF sy-subrc <> 0.
EXIT.
ENDIF.
APPEND xml_line TO xml_table.
CONCATENATE xml_string xml_line INTO xml_string.
ENDDO.
gi_ixml = cl_ixml=>create( ).
gi_document = gi_ixml->create_document( ).
gi_stream_factory = gi_ixml->create_stream_factory( ).
gi_resstream = gi_stream_factory->create_istream_itable( table = xml_table
size = gv_ressize ).
TRY.
CALL TRANSFORMATION ('ZCM_XSLT_TEST_XML')
SOURCE XML gi_resstream
RESULT evento = gs_evento.
CATCH cx_xslt_exception INTO xslt_error.
xslt_message = xslt_error->get_text( ).
WRITE:/ xslt_message .
ENDTRY.
Edited by: DSE on Feb 1, 2011 12:23 PM