Exporting Internal Table contents to an Excel File

...Previous   

23. Then Go to the Methods Tab. 

 

24. Write the Following Coding in the Corresponding Methods.

FILL_AIRLINE:

method FILL_AIRLINE .
* data declaration
  data LT_AIRLINE type WD_THIS->ELEMENTS_AIRLINE.
  data LS_AIRLINE like line of LT_AIRLINE.
  select distinct CARRID from SFLIGHT into table LT_AIRLINE.
* bind all the elements
  NODE->BIND_TABLE(
    NEW_ITEMS                        =  LT_AIRLINE
    SET_INITIAL_ELEMENTS = ABAP_TRUE ).
endmethod.
ONACTIONGET_FLIGHT_DETAILS:
method ONACTIONGET_FLIGHT_DETAILS .
  data LO_ND_AIRLINE type ref to IF_WD_CONTEXT_NODE.
  data LO_EL_AIRLINE type ref to IF_WD_CONTEXT_ELEMENT.
  data LS_AIRLINE type WD_THIS->ELEMENT_AIRLINE.
  data LV_ID like LS_AIRLINE-ID.
* navigate from <CONTEXT> to <AIRLINE> via lead selection
  LO_ND_AIRLINE = WD_CONTEXT->GET_CHILD_NODE( NAME = WD_THIS->WDCTX_AIRLINE ).
* get element via lead selection
  LO_EL_AIRLINE = LO_ND_AIRLINE->GET_ELEMENT(  ).
* get single attribute
  LO_EL_AIRLINE->GET_ATTRIBUTE(
    exporting
      NAME =  `ID`
    importing
      VALUE = LV_ID ).
  data LO_ND_SFLIGHT type ref to IF_WD_CONTEXT_NODE.
  data LO_EL_SFLIGHT type ref to IF_WD_CONTEXT_ELEMENT.
  data LT_SFLIGHT type WD_THIS->ELEMENTS_SFLIGHT.
  data LS_SFLIGHT type WD_THIS->ELEMENT_SFLIGHT.  
  
* navigate from <CONTEXT> to <SFLIGHT> via lead selection
  LO_ND_SFLIGHT = WD_CONTEXT->GET_CHILD_NODE( NAME = WD_THIS->WDCTX_SFLIGHT ).
  SELECT CARRID CONNID FLDATE CURRENCY PLANETYPE FROM SFLIGHT INTO
         CORRESPONDING FIELDS OF TABLE LT_SFLIGHT 
         WHERE CARRID = LV_ID.
         
   
  LO_ND_SFLIGHT->BIND_TABLE( LT_SFLIGHT ).           
endmethod.
ONACTIONEXPORT_TO_EXCEL:
method ONACTIONEXPORT_TO_EXCEL .
  data LO_ND_SFLIGHT type ref to IF_WD_CONTEXT_NODE.
  data LO_EL_SFLIGHT type ref to IF_WD_CONTEXT_ELEMENT.
  data LT_SFLIGHT type WD_THIS->ELEMENTS_SFLIGHT.
  data LS_SFLIGHT type WD_THIS->ELEMENT_SFLIGHT.
  data TEXT   type STRING.
  data XTEXT  type XSTRING.
* navigate from <CONTEXT> to <SFLIGHT> via lead selection
  LO_ND_SFLIGHT = WD_CONTEXT->GET_CHILD_NODE( NAME = WD_THIS->WDCTX_SFLIGHT ).
* get all declared attributes
  LO_ND_SFLIGHT->GET_STATIC_ATTRIBUTES_TABLE(
    importing
      TABLE = LT_SFLIGHT ).
  loop at LT_SFLIGHT into LS_SFLIGHT.
    concatenate TEXT LS_SFLIGHT-CARRID
                LS_SFLIGHT-CONNID
                LS_SFLIGHT-FLDATE
                LS_SFLIGHT-CURRENCY
                LS_SFLIGHT-PLANETYPE
                CL_ABAP_CHAR_UTILITIES=>NEWLINE into TEXT separated by
                CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB.
  endloop.
  call function 'SCMS_STRING_TO_XSTRING'
    exporting
      TEXT   = TEXT
    importing
      BUFFER = XTEXT.
  WDR_TASK=>CLIENT_WINDOW->CLIENT->ATTACH_FILE_TO_RESPONSE(
**path to the word file
    I_FILENAME = 'WDP.xls'
* String Variable
    I_CONTENT =  XTEXT
* File Type
    I_MIME_TYPE = 'EXCEL' ).    
endmethod. 

25. Save and Activate the Application. 

 

26. Create Webdynpro Application, save it and Test the Application.

Output:

 

1. Select the Airline Id LH from the Dropdown.

 

 2. It will display all the Entries with CARRID ‘LH’ from SFLIGHT Table. 

 

3. Now Press the Button Export To Excel. 

 

4. It will open a Popup for File Download. Press the Button Open. 

5. It will open an Excel File with the Following Entries. 

LH

400

20070428

EUR

A310-300

LH

400

20070526

EUR

A310-300

LH

400

20070721

EUR

A310-300

LH

401

20070525

EUR

A319

LH

401

20070622

EUR

A319

LH

401

20080523

EUR

A319

LH

2402

20070428

EUR

DC-10-10

LH

2402

20080426

EUR

DC-10-10

LH

2402

20080524

EUR

DC-10-10

LH

2407

20070428

EUR

727-200

LH

2407

20070721

EUR

727-200

LH

2407

20070818

EUR

727-200

 Note:

To Export the Internal Table to Word Document, replace the code
  WDR_TASK=>CLIENT_WINDOW->CLIENT->ATTACH_FILE_TO_RESPONSE(
    I_FILENAME   = 'WDP.xls'
    I_CONTENT     =  XTEXT
    I_MIME_TYPE = 'EXCEL' ).
With ,
  WDR_TASK=>CLIENT_WINDOW->CLIENT->ATTACH_FILE_TO_RESPONSE(
    I_FILENAME   = 'WDP.doc'
    I_CONTENT     =  XTEXT
    I_MIME_TYPE = 'WORD' ).
To Export the Internal Table to Text File, replace the Excel code 
with the Following
  WDR_TASK=>CLIENT_WINDOW->CLIENT->ATTACH_FILE_TO_RESPONSE(
    I_FILENAME    = 'WDP.txt'
    I_CONTENT     =  XTEXT
    I_MIME_TYPE = 'NOTEPAD' ).

Please send us your feedback/suggestions at webmaster@SAPTechnical.COM 

HomeContribute About Us Privacy Terms Of Use • Disclaimer • SafeCompanies: Advertise on SAPTechnical.COM | Post JobContact Us  

Graphic Design by Round the Bend Wizards

footer image footer image