Skip to Content

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.

Go to
the SE80 transaction and create a Web Dynpro Component , view and Application as below.

Untitled1.jpg

 
 
 
 
 
 
 
 
 
 
 
 

Step 2:

 

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.

Untitled 2.jpg

                  

Now node looks like the below

Untitled22.jpg

        

Step 3:

    

Go to code wizard as shown button and select table as shown
below

Untitled2.gif

        

Now click on Context and select the node sflight as shown below

Untitled.png        

Confirm the selected table fields to be part of the table.. Activate the view.

     Untitled7.png

Step 4:

   

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

Untitled14.png

         

Step 5:

    

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

 

Untitled12.png

On event handler of the button write the code as below, pls use code wizard to get the context data.

Untitled13.png

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

  
RETURN.


ENDIF.


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
  
IMPORTING

      stream = content

     size     = size.

 

* Attach the content to download

 
CALL METHOD cl_wd_runtime_services=>attach_file_to_response

EXPORTING

        i_filename  = ‘Sample.XML’

        i_content   = content

        i_mime_type = ‘XML’.

  

ENDMETHOD.

      

Application Testing:


Run the application and  you can see the UI as below , click on
download.

Untitled10.png

To report this post you need to login first.

Be the first to leave a comment

You must be Logged on to comment or reply to a post.

Leave a Reply