Applies to:

      Webdynpro ABAP

Summary

This article is to download Webdynpro ABAP table (header & line item) data in cell formatted excel sheet with colors, borders, filters. It was not possible to download data in Cell formatted Excel sheet using Webdynpro ABAP. To make this objective possible, we can use XML mapping.  For the XML mapping, create a dummy Excel Sheet with expected Cell formatting and save it as XML file. Use this XML tags in the method logic of Webdynpro ABAP coding.

Author(s):    KIRUTHIKA  P

Company:      L & T Infotech

Created on:   20 February 2012

Author Bio

              Kiruthika P is working as a SAP Technical ABAP consultant for one year in L & T Infotech. I am very much interested in learning new technologies in SAP. Currently I am working in Web Dynpro ABAP and ISU .

Introduction

This article is to download Webdynpro ABAP table (header & line item) data in cell formatted excel sheet with colors, borders, filters. It was not possible to download data in Cell formatted Excel sheet using Webdynpro ABAP. To make this objective possible, we can use XML mapping.  For the XML mapping, create a dummy Excel Sheet with expected Cell formatting and save it as XML file. Use this XML tags in the method logic of Webdynpro ABAP coding.

Objective

To download Webdynpro ABAP table (header & line item) data in cell formatted excel sheet with colors, borders, filters.

Steps

1. Create one Webdynpro Component

Go to SE80 -> Create Webdynpro component.

Give name of Webdynpro component and click Display Icon.

Then it will show one pop up message to create the component.

Click Yes.

2.Create the component with view and window.

  Give the description for Webdynpro component.

3. Save the component in local object or package.

4. Create a node (Node_Sflight) in Context of Component Controller.

5.Create a attribute in the node for table popin of type string.

6.Create a sub node (Node_sbook) under Node_Sflight.

7.Now context of Component Controller looks like as below.

8. Map the Context of Component Controller to view.

9. In layout of main View,Create one button “Get Flight” to get the flight details.

  Under the On_action   properties of this element create one event  “Flight_Details”.

10.Create one table to display the header data flight details.

11.The table is binded to ‘Node_Sflight’.

12.Insert one new table column for popin from the table.

13.In that column, Insert cell variant.

14.Go to the properties of “Table_popin_toggle_cell” in table column and provide ‘TOGGLE_CELL’ in

   ‘Variant key’ property.

15.Go to the properties of Table Column and provide ‘TOGGLE_CELL’ in ‘Selected Cell Variant’ property

   as in figure.

16.Go to the properties of ‘Table’ and bind Selected Popin property with table_popin attribute of node_Sflight.

17.Create a popin window by Insert Table popin.

18.In that popin, create a transparent container.

19.Create a table in the container to show the line data details of a particular flight.

20.The table in the popin is binded to subnode ‘Node_Sbook’.

     

21.Create another button “Export To Excel” which is used to export data from  table to Excel Sheet.

Under the On_action properties of this element create one event “Export_Excel”.

22.Go to methods tab. Then write logic for all the methods.

23.In the method list, Go to Get_Flights and click the code wizard.

24. By the code wizard, read the main node and sub node.

25.In Export_To _Excel method ,write logic to export data with formats such as borders,Colors,  etc.

26.In Webdynpro ABAP, no direct code for cell formatted excels. So create one dummy excel sheet with expected cell formatted features (colors, borders, filter, headers, etc).

27.Save the Excel file as XML data.

28. XML data mapped Excel file is in this format.

29.Open this file with notepad and map this XML data to coding.

30.The resulting XML tags are appended to code of Export_to_Excel.

31.After creating all methods, save and activate it.

32.Create a Webdynpro application for the Webdynpro component.

      

   

33.Then Save and Activate the entire component.

34.Go to web Dynpro application and then test the application.

     

Code Sample:

            Step 1.Method  To_get_Flight_details.

                 To get list of flights details by the method.

               

METHOD onactionto_get_flights .
* Declarations
 
DATA lo_nd_node_sflight TYPE REF TO if_wd_context_node.

  DATA lo_el_node_sflight TYPE REF TO if_wd_context_element.
 
DATA ls_node_sflight    TYPE        wd_this->element_node_sflight.
 
DATA lt_sflight         TYPE        wd_this->elements_node_sflight.
*   navigate from to via lead selection
  lo_nd_node_sflight = wd_context->get_child_node( name = wd_this->wdctx_node_sflight ).
*   To get static attributes table
  lo_nd_node_sflight->get_static_attributes_table(IMPORTING
 
table = lt_sflight ).
*To fill internal table
 
SELECT * FROM sflight
INTO CORRESPONDING FIELDS OF TABLE lt_sflight.
*   get element via lead selection
  lo_el_node_sflight = lo_nd_node_sflight->get_element( ).
*   @TODO handle not set lead selection
 
IF lo_el_node_sflight IS INITIAL.
 
ENDIF.*   To bind the internal table to main node
  lo_nd_node_sflight->bind_table( lt_sflight ).**********———————————————******************
*   Declarations of sub node
 
DATA lo_nd_node_sbook TYPE REF TO if_wd_context_node.
 
DATA lo_el_node_sbook TYPE REF TO if_wd_context_element.
 
DATA ls_node_sbook    TYPE        wd_this->element_node_sbook.
 
DATA lt_sbook         TYPE        wd_this->elements_node_sbook .
* navigate from to via lead selection
  lo_nd_node_sbook = wd_context->path_get_node( path =
`NODE_SFLIGHT.NODE_SBOOK` ).
* @TODO handle not set lead selection
 
IF lo_el_node_sbook IS INITIAL.
 
ENDIF.
* To fill the popin internal table based on values in first internal table
 
SELECT * FROM sbook
    
INTO CORRESPONDING FIELDS OF TABLE  lt_sbook
   
FOR ALL ENTRIES IN lt_sflight
       
WHERE carrid = lt_sflight-carrid AND
                                  connid = lt_sflight-connid
AND
                                  fldate = lt_sflight-fldate.
* To bind internal table to the node
 
IF lo_nd_node_sbook IS NOT INITIAL.
    lo_nd_node_sbook->bind_table( lt_sbook ).
 
ENDIF

Step 2. Method_Linedata

         Next to get the lineitem data for particular header row.

METHOD onactionlinedata .* Declarations
 
DATA lo_nd_node_sflight TYPE REF TO if_wd_context_node.
 
DATA lo_el_node_sflight TYPE REF TO if_wd_context_element.
 
DATA ls_node_sflight    TYPE        wd_this->element_node_sflight.
 
DATA lt_sflight         TYPE        wd_this->elements_node_sflight.
*   navigate from to via lead selection
  lo_nd_node_sflight = wd_context->get_child_node( name = wd_this->wdctx_node_sflight).
*   get element via lead selection
  lo_el_node_sflight = lo_nd_node_sflight->get_element( ).
* Declarations
 
DATA lt_sbook         TYPE        wd_this->elements_node_sbook.
 
DATA lo_nd_node_sbook TYPE REF TO if_wd_context_node.
 
DATA lo_el_node_sbook TYPE REF TO if_wd_context_element.
 
DATA ls_sbook         TYPE        wd_this->element_node_sbook.
* navigate from to via lead selection
  lo_nd_node_sbook = wd_context->path_get_node (path =
`NODE_SFLIGHT.NODE_SBOOK` ).
* @TODO handle non existant child
 
IF lo_nd_node_sbook IS NOT INITIAL.
    lo_el_node_sbook = lo_nd_node_sbook->get_element( ).
 
ENDIF.
* Filling the linedata internal table
 
SELECT * FROM sbook
   
INTO CORRESPONDING FIELDS OF TABLE lt_sbook
   
FOR ALL ENTRIES IN lt_sflight
   
WHERE carrid = lt_sflight-carrid AND
           connid = lt_sflight-connid
AND
           fldate = lt_sflight-fldate.
* To bind internal table to line data node
 
IF lo_nd_node_sbook IS NOT INITIAL.


   

lo_nd_node_sbook->bind_table( lt_sbook ).
 
ENDIF.ENDMETHOD.

Step 3. Method_Export_To_Excel

       And now the final piece of the article  is to take action in response to the click  of  button “EXPORT_TO_EXCEL”

METHOD onactionexport_to_excel .*  declarations
 
DATA lo_nd_sflight TYPE REF TO if_wd_context_node.
 
DATA lo_el_sflight TYPE REF TO if_wd_context_element.
 
DATA ls_sflight TYPE wd_this->element_sflight.
 
DATA lt_sflight TYPE wd_this->elements_sflight.

  DATA text  TYPE string.
 
DATA xtext TYPE xstring.
 
DATA lv_sno(3) TYPE n.
 
DATA lv_space  TYPE c VALUE ‘ ‘.
*   navigate from to via lead selection
  lo_nd_sflight = wd_context->get_child_node( name = wd_this->wdctx_sflight ).
*   get element via lead selection
  lo_el_sflight = lo_nd_sflight->get_element( ).

  DATA : lv_parent_index TYPE i.
 
CALL METHOD lo_el_sflight->get_index
    RECEIVING
      my_index = lv_parent_index.
*   get all declared attributes
  lo_nd_sflight->get_static_attributes_table(
 
IMPORTING
   
table = lt_sflight ).
*  declarations
 
DATA lo_nd_sbook TYPE REF TO if_wd_context_node.
 
DATA lo_el_sbook TYPE REF TO if_wd_context_element.
 
DATA ls_sbook TYPE wd_this->element_sbook.
 
DATA lt_sbook TYPE wd_this->elements_sbook.
*Assign initial value
  lv_sno =
1.

  lo_nd_sbook =  wd_context->path_get_node( path = `SFLIGHT.SBOOK` ).**************************************************************************** declarations for xml data
 
DATA p_t_xml_data TYPE TABLE OF tline.
 
FIELD-SYMBOLS TYPE tline.
* append xml data to this code
 
APPEND INITIAL LINE TO p_t_xml_data
 
ASSIGNING .
 
MOVE :’ TO  -tdline.
 
CONCATENATE text -tdline  cl_abap_char_utilities=>newline INTO text .

  APPEND INITIAL LINE TO p_t_xml_data
 
ASSIGNING .
 
MOVE :’ TO  -tdline.
 
CONCATENATE text -tdline  cl_abap_char_utilities=>newline INTO text .

  APPEND INITIAL LINE TO p_t_xml_data
 
ASSIGNING .
 
MOVE :  -tdline.
  CONCATENATE text -tdline  cl_abap_char_utilities=>newline INTO text .

  APPEND INITIAL LINE TO p_t_xml_data
 
ASSIGNING .
 
MOVE : ‘xmlns:o=”urn:schemas-microsoft-com:office:office”‘ TO  -tdline.
 
CONCATENATE text -tdline  cl_abap_char_utilities=>newline INTO text .

  APPEND INITIAL LINE TO p_t_xml_data
 
ASSIGNING .
 
MOVE : ‘xmlns:x=”urn:schemas-microsoft-com:office:excel”‘ TO  -tdline.
 
CONCATENATE text -tdline  cl_abap_char_utilities=>newline INTO text .

  APPEND INITIAL LINE TO p_t_xml_data
 
ASSIGNING .
 
MOVE : ‘xmlns:ss=”urn:schemas-microsoft-com:office:spreadsheet”‘ TO  -tdline.
 
CONCATENATE text -tdline  cl_abap_char_utilities=>newline INTO text .

  APPEND INITIAL LINE TO p_t_xml_data
 
ASSIGNING .
 
MOVE : ‘xmlns:html=”https://www.w3.org/TR/REC-html40“>’ TO  -tdline.
 
CONCATENATE text -tdline  cl_abap_char_utilities=>newline INTO text.

  APPEND INITIAL LINE TO p_t_xml_data
 
ASSIGNING .
 
MOVE :’ TO  -tdline.
 
CONCATENATE text -tdline  cl_abap_char_utilities=>newline INTO text.

  APPEND INITIAL LINE TO p_t_xml_data
 
ASSIGNING .
 
MOVE :281153’ TO  -tdline.
 
CONCATENATE text -tdline  cl_abap_char_utilities=>newline INTO text.

  APPEND INITIAL LINE TO p_t_xml_data
 
ASSIGNING .
 
MOVE :295231’ TO  -tdline.
 
CONCATENATE text -tdline  cl_abap_char_utilities=>newline INTO text.

  APPEND INITIAL LINE TO p_t_xml_data
 
ASSIGNING .
 
MOVE :2011-12-05T10:59:08Z’ TO  -tdline.
 
CONCATENATE text -tdline  cl_abap_char_utilities=>newline INTO text.

  APPEND INITIAL LINE TO p_t_xml_data
 
ASSIGNING .
 
MOVE :2011-12-27T06:14:56Z’ TO  -tdline.
 
CONCATENATE text -tdline  cl_abap_char_utilities=>newline INTO text.

  APPEND INITIAL LINE TO p_t_xml_data
 
ASSIGNING .
 
MOVE : ‘  lnt’ TO  -tdline.
 
CONCATENATE text -tdline  cl_abap_char_utilities=>newline INTO text.

  APPEND INITIAL LINE TO p_t_xml_data
 
ASSIGNING .
 
MOVE :12.00’ TO  -tdline.
 
CONCATENATE text -tdline  cl_abap_char_utilities=>newline INTO text.

  APPEND INITIAL LINE TO p_t_xml_data
 
ASSIGNING .
 
MOVE : ‘ ’ TO  -tdline.
 
CONCATENATE text -tdline  cl_abap_char_utilities=>newline INTO text.

  APPEND INITIAL LINE TO p_t_xml_data
 
ASSIGNING .
 
MOVE :’ TO  -tdline.
 
CONCATENATE text -tdline  cl_abap_char_utilities=>newline INTO text.

  APPEND INITIAL LINE TO p_t_xml_data
 
ASSIGNING .
 
MOVE :7560’ TO  -tdline.
 
CONCATENATE text -tdline  cl_abap_char_utilities=>newline INTO text.

  APPEND INITIAL LINE TO p_t_xml_data
 
ASSIGNING .
 
MOVE :7500’ TO  -tdline.
 
CONCATENATE text -tdline  cl_abap_char_utilities=>newline INTO text.

  APPEND INITIAL LINE TO p_t_xml_data
 
ASSIGNING .
 
MOVE :360’ TO  -tdline.
 
CONCATENATE text -tdline  cl_abap_char_utilities=>newline INTO text.

  APPEND INITIAL LINE TO p_t_xml_data
 
ASSIGNING .
 
MOVE :105’ TO  -tdline.
 
CONCATENATE text -tdline  cl_abap_char_utilities=>newline INTO text.

  APPEND INITIAL LINE TO p_t_xml_data
 
ASSIGNING .
 
MOVE : ‘   False’ TO  -tdline.
 
CONCATENATE text -tdline  cl_abap_char_utilities=>newline INTO text.

  APPEND INITIAL LINE TO p_t_xml_data
 
ASSIGNING .
 
MOVE :False’ TO  -tdline.
 
CONCATENATE text -tdline  cl_abap_char_utilities=>newline INTO text.

  APPEND INITIAL LINE TO p_t_xml_data
 
ASSIGNING .
 
MOVE : ‘ ’ TO  -tdline.
 
CONCATENATE text -tdline  cl_abap_char_utilities=>newline INTO text.

  APPEND INITIAL LINE TO p_t_xml_data
 
ASSIGNING .
 
MOVE :’ TO  -tdline.
 
CONCATENATE text -tdline  cl_abap_char_utilities=>newline INTO text.

  APPEND INITIAL LINE TO p_t_xml_data
 
ASSIGNING .
 
MOVE :