This document explains how to convert table data and download as a XML file
Step by Step Process
Step 1: Create a Web Dynpro Component.
the SE80 transaction and create a Web Dynpro Component , view and Application as below.
Navigate to Main view and go to context tab , create a node SFLIGHT with cardinality 0:n and selection 0:1 , go to node sflight and right click and
navigate to Create using Wizard and navigate again to attributes from component of structure . Give the structure as shown below, select the required fields.
Now node looks like the below
Go to code wizard as shown button and select table as shown
Now click on Context and select the node sflight as shown below
Confirm the selected table fields to be part of the table.. Activate the view.
Go to INIT method of the main view and write the code to fill the table.
A simple select would do the needful , post fetching the results simply attach the results to the node sflight as below
Create a tool bar and place a button as shown below , change the button text to “To XML “ create a event handler for the button from the button properties to write the code to download to XML file..
On event handler of the button write the code as below, pls use code wizard to get the context data.
Code in the event handler:
METHOD onactionon_download .
DATA lo_nd_sflight TYPE REF TO if_wd_context_node.
DATA lt_sflight TYPE wd_this->elements_sflight.
* navigate from <CONTEXT> to <SFLIGHT> via lead selection
lo_nd_sflight = wd_context->get_child_node( name = wd_this->wdctx_sflight ).
lo_nd_sflight->get_static_attributes_table( IMPORTING table = lt_sflight ).
IF lt_sflight IS INITIAL.
* error handling
DATA l_xml TYPE REF TO cl_xml_document.
DATA content TYPE xstring.
DATA size TYPE sytabix.
* Create object
CREATE OBJECT l_xml.
CALL METHOD l_xml->create_with_data( dataobject = lt_sflight ).
* rendering to xstring
CALL METHOD l_xml->render_2_xstring
stream = content
size = size.
* Attach the content to download
CALL METHOD cl_wd_runtime_services=>attach_file_to_response
i_filename = ‘Sample.XML’
i_content = content
i_mime_type = ‘XML’.
Run the application and you can see the UI as below , click on