SAP R/3 форум ABAP консультантов
Russian ABAP Developer's Club

Home - FAQ - Search - Memberlist - Usergroups - Profile - Log in to check your private messages - Register - Log in - English
Blogs - Weblogs News

Exampe XML data conversions



 
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> Programming Techniques | Приемы программирования -> Conversion
View previous topic :: View next topic  
Author Message
admin
Администратор
Администратор



Joined: 01 Sep 2007
Posts: 1640

PostPosted: Mon Mar 17, 2008 12:38 am    Post subject: Exampe XML data conversions Reply with quote

Code:
REPORT z_xml_example.

DATA: it_table LIKE dd02l OCCURS 0.

DATA: l_dom TYPE REF TO if_ixml_element,
       m_document TYPE REF TO if_ixml_document,
       g_ixml TYPE REF TO if_ixml,
       w_string TYPE xstring,
       w_size TYPE i,
       w_result TYPE i,
       w_line TYPE string,
       it_xml TYPE dcxmllines,
       s_xml LIKE LINE OF it_xml,
       w_rc LIKE sy-subrc.

START-OF-SELECTION.
  SELECT * FROM dd02l INTO TABLE it_table
   UP TO 10 ROWS.

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.

********************************************
**** visualize iXML (DOM)               ****
********************************************
  WRITE / 'displaying DOM:'.
  CALL FUNCTION 'SDIXML_DOM_TO_SCREEN'
       EXPORTING
            document    = m_document
       EXCEPTIONS
            no_document = 1
            OTHERS      = 2.
  IF sy-subrc = 0.
    WRITE  'ok'.
  ELSE.
    WRITE: 'Err =', sy-subrc.
  ENDIF.

********************************************
**** convert DOM to XML doc (table)     ****
********************************************
  WRITE / 'converting DOM TO XML:'.
  CALL FUNCTION 'SDIXML_DOM_TO_XML'
    EXPORTING
       document = m_document
*     PRETTY_PRINT        = ' '
    IMPORTING
       xml_as_string = w_string
       size = w_size
    TABLES
       xml_as_table = it_xml
    EXCEPTIONS
       no_document = 1
       OTHERS = 2.
  IF sy-subrc = 0.
    WRITE  'ok'.
  ELSE.
    WRITE: 'Err =', sy-subrc.
  ENDIF.

  WRITE: / 'XML as string of size:', w_size,
         / w_string.

  DESCRIBE TABLE it_xml LINES w_result.
  WRITE: / 'XML as table of', w_result,  'lines:'..
  LOOP AT it_xml INTO s_xml.
    WRITE s_xml.
  ENDLOOP.

  WRITE / 'end of processing'.
* end of code
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> Programming Techniques | Приемы программирования -> Conversion All times are GMT + 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG.
SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG.
Every effort is made to ensure content integrity. Use information on this site at your own risk.