将内表数据生产XML

*&---------------------------------------------------------------------*
*& Report  Z_XML
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  Z_XML.
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 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值