Quantcast
Channel: SCN : Document List - ABAP Development
Viewing all articles
Browse latest Browse all 935

Download Multiple Internal Tables in Single Excel Sheet

$
0
0

Download Multiple Internal Tables in Single Excel Sheet

 

 

Objective:

 

Some times we need to download multiple internal tables in single excel files as per requirement. Internal tables having different structure at that time we can download multiple internal tables in single excel sheet using GUI_DOWNLOAD function module.

 

Simple Solution:

 

Using append function in GUI_DOWNLOAD function module

 

Sample Code:

 


**** Types Declaration
TYPES: BEGIN OF ty_header,
        fld(20) TYPE c,
        END OF ty_header,

        BEGIN OF ty_t001,
        bukrs TYPE t001-bukrs,
        butxt TYPE t001-butxt,
        ort01 TYPE t001-ort01,
        END OF ty_t001,

        BEGIN OF ty_sflight,
        carrid TYPE sflight-carrid,
        connid TYPE sflight-connid,
        fldate TYPE sflight-fldate,
        price  TYPE sflight-price,
        END OF ty_sflight.

**** Internal table Declaration
DATA: it_t001 TYPE TABLE OF ty_t001,
       it_sflight TYPE TABLE OF ty_sflight,
       it_header_1 TYPE TABLE OF ty_header,
       it_header_2 TYPE TABLE OF ty_header.

**** WorkArea Declaration
DATA: wa_t001 TYPE ty_t001,
       wa_sflight TYPE ty_sflight,
       wa_header TYPE ty_header.

**** getting data from t001 to it_t001
SELECT bukrs
        butxt
        ort01
        INTO TABLE it_t001 FROM t001 UP TO 10 ROWS.

**** Header Declaration for t001
wa_header-fld = 'Company Code'.
APPEND wa_header TO it_header_1.
CLEAR wa_header.
wa_header-fld = 'Name of Company Code or Company'.
APPEND wa_header TO it_header_1.
CLEAR wa_header.
wa_header-fld = 'City'.
APPEND wa_header TO it_header_1.
CLEAR wa_header.

**** getting data from sflight to it_sflight
SELECT carrid
        connid
        fldate
        price
        INTO TABLE it_sflight FROM sflight UP TO 10 ROWS.

**** Header Declaration for sflight
wa_header-fld = 'Airline Code'.
APPEND wa_header TO it_header_2.
CLEAR wa_header.
wa_header-fld = 'Flight Connection Number'.
APPEND wa_header TO it_header_2.
CLEAR wa_header.
wa_header-fld = 'Flight date'.
APPEND wa_header TO it_header_2.
CLEAR wa_header.
wa_header-fld = 'Airfare'.
APPEND wa_header TO it_header_2.
CLEAR wa_header.

**** To download data to excel
CALL FUNCTION 'GUI_DOWNLOAD'
   EXPORTING
     filename              = 'D:/test.xls'
     write_field_separator = 'X'
     append                = ' '
   TABLES
     data_tab              = it_t001
     fieldnames            = it_header_1.

CALL FUNCTION 'GUI_DOWNLOAD'
   EXPORTING
     filename              = 'D:/test.xls'
     write_field_separator = 'X'
    append                = 'X'                
   TABLES
     data_tab              = it_sflight
     fieldnames             = it_header_2.

 

 

Output

 

 

 

Regards,

Ramesh.T


Viewing all articles
Browse latest Browse all 935

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>