2008 Apr 26 11:43 AM
hi,
I'm trying to convert an xml file to an internal table. in the process, i'm stuck with the function module "SDIXML_DOM_TO_DATA".
Can anyone help me out in using this FM..?
Regards,
Satish.S
2008 Apr 26 11:50 AM
Hi,
Check this Report....
report z.
type-pools truxs.
data: it_table like t001 occurs 0.
data: l_dom TYPE REF TO IF_IXML_ELEMENT,
m_document TYPE REF TO IF_IXML_DOCUMENT,
m_xmldoc TYPE REF TO CL_XML_DOCUMENT,
g_ixml TYPE REF TO IF_IXML,
l_iref_pstreamfactory TYPE REF TO if_ixml_stream_factory,
l_iref_postream TYPE REF TO if_ixml_ostream,
It_CONVERTED_DATA TYPE TRUXS_XML_TABLE,
it_converted_line like line of It_CONVERTED_DATA,
w_result TYPE I,
w_rc like sy-subrc,
s_node type string.
start-of-selection.
select * from t001 into table it_table.
end-of-selection.
********************************************
**** initialize iXML-Framework ****
********************************************
write: / 'initialiazing iXML:'.
class cl_ixml definition load.
g_ixml = cl_ixml=>create( ).
check not g_ixml is initial.
write: 'ok'.
********************************************
**** create DOM from SAP data ****
********************************************
write: / 'creating iXML doc:'.
m_document = g_ixml->create_document( ).
check not m_document is initial.
write: 'ok'.
write: / 'converting DATA TO DOM 1:'.
CALL FUNCTION 'SDIXML_DATA_TO_DOM'
EXPORTING
NAME = 'IT_TABLE'
DATAOBJECT = it_table[]
IMPORTING
DATA_AS_DOM = l_dom
CHANGING
DOCUMENT = m_document
EXCEPTIONS
ILLEGAL_NAME = 1
OTHERS = 2.
if sy-subrc = 0. write 'ok'.
else. write: 'Err =', sy-subrc.
endif.
check not l_dom is initial.
write: / 'appending DOM to iXML doc:'.
w_rc = m_document->append_child( new_child = l_dom ).
if w_rc is initial. write 'ok'.
else. write: 'Err =', w_rc.
endif.
********************************************
**** creating object XML doc ****
********************************************
write: / 'creating XML document:'.
create object m_xmldoc.
check not m_xmldoc is initial.
write 'ok'.
write: / 'getting XML from DOM:'.
w_rc = m_xmldoc->create_with_dom( document = m_document ).
if w_rc is initial. write 'ok'.
else. write: 'Err =', w_rc.
endif.
********************************************
**** visualize object XML doc **************
********************************************
write: / 'displaying XML document:'.
call method m_xmldoc->display.
write: / 'select node from XML document:'.
s_node = m_xmldoc->call_f4( ).
write s_node.
********************************************
**** convert DOM to XML doc (table) ****
**** method 2 - OO ****
********************************************
write: / 'creating stream factory:'.
l_iref_pstreamfactory = g_ixml->create_stream_factory( ).
check not l_iref_pstreamfactory is initial.
write 'ok'.
write: / 'creating ostream table:'.
l_iref_postream = l_iref_pstreamfactory->create_ostream_itable(
table = it_converted_data ).
check not l_iref_postream is initial.
write 'ok'.
write: / 'rendering (filling table):'.
CALL METHOD m_document->render( ostream = l_iref_postream ).
* -- how many bytes were written to the table?
w_result = l_iref_postream->get_num_written_raw( ).
write: / w_result, 'bytes were written to the table:'.
loop at it_converted_data into it_converted_line.
write it_converted_line-data.
endloop.
write: / 'end of processing'.
* end of code
Reward points if useful.... (Don't forget)
Regards
AK
2008 Apr 26 11:50 AM
Hi,
Check this Report....
report z.
type-pools truxs.
data: it_table like t001 occurs 0.
data: l_dom TYPE REF TO IF_IXML_ELEMENT,
m_document TYPE REF TO IF_IXML_DOCUMENT,
m_xmldoc TYPE REF TO CL_XML_DOCUMENT,
g_ixml TYPE REF TO IF_IXML,
l_iref_pstreamfactory TYPE REF TO if_ixml_stream_factory,
l_iref_postream TYPE REF TO if_ixml_ostream,
It_CONVERTED_DATA TYPE TRUXS_XML_TABLE,
it_converted_line like line of It_CONVERTED_DATA,
w_result TYPE I,
w_rc like sy-subrc,
s_node type string.
start-of-selection.
select * from t001 into table it_table.
end-of-selection.
********************************************
**** initialize iXML-Framework ****
********************************************
write: / 'initialiazing iXML:'.
class cl_ixml definition load.
g_ixml = cl_ixml=>create( ).
check not g_ixml is initial.
write: 'ok'.
********************************************
**** create DOM from SAP data ****
********************************************
write: / 'creating iXML doc:'.
m_document = g_ixml->create_document( ).
check not m_document is initial.
write: 'ok'.
write: / 'converting DATA TO DOM 1:'.
CALL FUNCTION 'SDIXML_DATA_TO_DOM'
EXPORTING
NAME = 'IT_TABLE'
DATAOBJECT = it_table[]
IMPORTING
DATA_AS_DOM = l_dom
CHANGING
DOCUMENT = m_document
EXCEPTIONS
ILLEGAL_NAME = 1
OTHERS = 2.
if sy-subrc = 0. write 'ok'.
else. write: 'Err =', sy-subrc.
endif.
check not l_dom is initial.
write: / 'appending DOM to iXML doc:'.
w_rc = m_document->append_child( new_child = l_dom ).
if w_rc is initial. write 'ok'.
else. write: 'Err =', w_rc.
endif.
********************************************
**** creating object XML doc ****
********************************************
write: / 'creating XML document:'.
create object m_xmldoc.
check not m_xmldoc is initial.
write 'ok'.
write: / 'getting XML from DOM:'.
w_rc = m_xmldoc->create_with_dom( document = m_document ).
if w_rc is initial. write 'ok'.
else. write: 'Err =', w_rc.
endif.
********************************************
**** visualize object XML doc **************
********************************************
write: / 'displaying XML document:'.
call method m_xmldoc->display.
write: / 'select node from XML document:'.
s_node = m_xmldoc->call_f4( ).
write s_node.
********************************************
**** convert DOM to XML doc (table) ****
**** method 2 - OO ****
********************************************
write: / 'creating stream factory:'.
l_iref_pstreamfactory = g_ixml->create_stream_factory( ).
check not l_iref_pstreamfactory is initial.
write 'ok'.
write: / 'creating ostream table:'.
l_iref_postream = l_iref_pstreamfactory->create_ostream_itable(
table = it_converted_data ).
check not l_iref_postream is initial.
write 'ok'.
write: / 'rendering (filling table):'.
CALL METHOD m_document->render( ostream = l_iref_postream ).
* -- how many bytes were written to the table?
w_result = l_iref_postream->get_num_written_raw( ).
write: / w_result, 'bytes were written to the table:'.
loop at it_converted_data into it_converted_line.
write it_converted_line-data.
endloop.
write: / 'end of processing'.
* end of code
Reward points if useful.... (Don't forget)
Regards
AK
2008 Apr 26 1:15 PM
hi,
Thanx for ur reply. well, ur code seems to be too spicy for me, i'm a beginer in abap...! i shall tell u my need. i converted my int table that had 4 records, to an xml file. it was done successfully. now i need to revert the process. ie: convert the XML file containing the 4 records to an int table. plz post a code which satisfies my need...
Regards,
Satish.S