Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

download report output to excel

VenuAnumayam
Participant
0 Kudos

Hello Experts,

Could you please tell me how I can write code to download the output list of a report into to a excel file?

Thnx very much.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi ravi,

Use Gui_download Function module to download data in to excel sheet before that you have get the data into internal table.

Thanks

Sunil.

5 REPLIES 5

Former Member
0 Kudos

Hi,

pass your final internal table to FM as below

DATA: LV_FILE LIKE IBIPPARMS-PATH VALUE 'C:\detail',

LV_FILE1 LIKE RLGRAP-FILENAME.

PERFORM EXCEL_SUMMARY_HEADER.

CALL FUNCTION 'F4_FILENAME'

EXPORTING

PROGRAM_NAME = SYST-REPID

DYNPRO_NUMBER = SYST-DYNNR

FIELD_NAME = ' '

IMPORTING

FILE_NAME = LV_FILE

EXCEPTIONS

OTHERS = 1.

IF SY-SUBRC EQ 0.

IF LV_FILE IS INITIAL.

LV_FILE = 'c:\detail'.

ENDIF.

LV_FILE1 = LV_FILE.

CALL FUNCTION 'EXCEL_OLE_STANDARD_DAT'

EXPORTING

FILE_NAME = LV_FILE1

DATA_SHEET_NAME = 'SUMMARY'

TABLES

<b> DATA_TAB = IT_EXCEL_SUMMARY</b> EXCEPTIONS

FILE_NOT_EXIST = 1

FILENAME_EXPECTED = 2

COMMUNICATION_ERROR = 3

OLE_OBJECT_METHOD_ERROR = 4

OLE_OBJECT_PROPERTY_ERROR = 5

INVALID_FILENAME = 6

INVALID_PIVOT_FIELDS = 7

DOWNLOAD_PROBLEM = 8

OTHERS = 9.

IF SY-SUBRC <> 0.

ENDIF.

ENDIF.

Former Member
0 Kudos

Hi ravi,

Use Gui_download Function module to download data in to excel sheet before that you have get the data into internal table.

Thanks

Sunil.

Former Member
0 Kudos

Former Member
0 Kudos

Hi Ravi,

&----


*& Report Z_TEST_DATA *

*& *

&----


*& *

*& *

&----


REPORT Z_MM_RP_PO_DOWNLOAD LINE-SIZE 500.

----


  • TABLES *

----


TABLES: EKKO, " Purchasing document header data

EKPO. " Purchasing document item

----


  • FLAGS *

----


DATA: V_FLAG(1).

----


  • INTERNAL TABLE DECLARATION *

----


*--- Internal table to hold the purchasing documents

DATA: BEGIN OF IT_EKKO OCCURS 0,

EBELN LIKE EKKO-EBELN, " Purchasing Document

BUKRS LIKE EKKO-BUKRS,

BSTYP LIKE EKKO-BSTYP, " Purchasing document category

BSART LIKE EKKO-BSART, " Purchasing document type

AEDAT LIKE EKKO-AEDAT, " Created on

LIFNR LIKE LFA1-LIFNR, " Vendor No

NAME1 LIKE LFA1-NAME1, " Name1

STRAS LIKE LFA1-STRAS,

ADRNR LIKE LFA1-ADRNR,

ORT02 LIKE LFA1-ORT02,

REGIO LIKE LFA1-REGIO,

PSTLZ LIKE LFA1-PSTLZ,

ORT01 LIKE LFA1-ORT01,

ZTERM LIKE EKKO-ZTERM,

EKORG LIKE EKKO-EKORG,

EKGRP LIKE EKKO-EKGRP,

WAERS LIKE EKKO-WAERS,

BEDAT LIKE EKKO-BEDAT,

STATU LIKE EKKO-STATU,

END OF IT_EKKO.

*--- Internal table to hold the Purch. doc item data

DATA: BEGIN OF IT_EKPO OCCURS 0,

EBELN LIKE EKPO-EBELN, " Purch. Doc no

EBELP LIKE EKPO-EBELP, " Purch. Doc Item

PSTYP LIKE EKPO-PSTYP,

MATNR LIKE EKPO-MATNR, " Material Number

MAKTX LIKE MAKT-MAKTX,

MATKL LIKE EKPO-MATKL, " Material Group

MENGE LIKE EKPO-MENGE, " PO Quantity,

MEINS LIKE EKPO-MEINS,

NETPR LIKE EKPO-NETPR, " Net price

WERKS LIKE EKPO-WERKS,

PEINH LIKE EKPO-PEINH,

BPRME LIKE EKPO-BPRME,

BANFN LIKE EKPO-BANFN,

BNFPO LIKE EKPO-BNFPO,

END OF IT_EKPO.

DATA : BEGIN OF IT_FINAL1 OCCURS 0,

FIELD1(15) TYPE C,

FIELD2(15) TYPE C,

FIELD3(15) TYPE C,

FIELD4(15) TYPE C,

FIELD5(40) TYPE C,

FIELD6(15) TYPE C,

FIELD7(15) TYPE C,

FIELD8(15) TYPE C,

FIELD9(15) TYPE C,

FIELD10(15) TYPE C,

FIELD11(15) TYPE C,

FIELD12(15) TYPE C,

FIELD13(15) TYPE C,

FIELD14(15) TYPE C,

FIELD15(15) TYPE C,

FIELD16(15) TYPE C,

FIELD17(15) TYPE C,

FIELD18(15) TYPE C,

FIELD19(15) TYPE C,

END OF IT_FINAL1.

----


  • SELECTION SCREEN

----


SELECTION-SCREEN BEGIN OF BLOCK BLK1 WITH FRAME TITLE TEXT-001.

SELECT-OPTIONS : S_EBELN FOR EKKO-EBELN OBLIGATORY." Purchasing Doc

SELECTION-SCREEN END OF BLOCK BLK1.

----


  • AT SELECTION SCREEN

----


AT SELECTION-SCREEN ON S_EBELN.

*--- Perform to validate purchasing document

PERFORM VALIDATE_PURCH_DOC.

----


  • TOP-OF-PAGE *

----


TOP-OF-PAGE.

----


  • START-OF-SELECTION *

----


START-OF-SELECTION.

*--- Perform to get the po data

PERFORM GET_DATA.

PERFORM DOWNLOAD.

----


  • END-OF-SELECTION *

----


*END-OF-SELECTION.

----


  • END-OF-PAGE *

----


END-OF-PAGE.

&----


*& Form VALIDATE_PURCH_DOC

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM VALIDATE_PURCH_DOC.

DATA: LV_EBELN LIKE EKKO-EBELN.

IF NOT S_EBELN[] IS INITIAL.

SELECT SINGLE EBELN

INTO LV_EBELN

FROM EKKO

WHERE EBELN IN S_EBELN.

IF SY-SUBRC <> 0.

MESSAGE S000(ZLKPL_MSGCLASS) WITH 'Enter a Material Number'.

V_FLAG = 'X'.

ENDIF.

ENDIF.

ENDFORM. " VALIDATE_PURCH_DOC

&----


*& Form GET_DATA

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM GET_DATA.

*--- Perform to get the Purch. doc

PERFORM SELECT_PO_DATA.

*--- Perform to get the Purh. Doc

PERFORM SELECT_PO_ITEM_DATA.

ENDFORM. " GET_DATA

&----


*& Form SELECT_PO_DATA

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM SELECT_PO_DATA.

DATA: LV_MESG(80). " Message

*--- Select construct to get the purchasing documents from 'EKKO'

SELECT A~EBELN

A~BUKRS

A~BSTYP

A~BSART

A~AEDAT

B~LIFNR

B~NAME1

B~STRAS

B~ADRNR

B~ORT02

B~REGIO

B~PSTLZ

B~ORT01

A~ZTERM

A~EKORG

A~EKGRP

A~WAERS

A~BEDAT

A~STATU

INTO TABLE IT_EKKO

FROM EKKO AS A

INNER JOIN LFA1 AS B

ON ALIFNR EQ BLIFNR

WHERE A~EBELN IN S_EBELN.

IF SY-SUBRC = 0.

SORT IT_EKKO BY EBELN.

ELSE.

LV_MESG = 'No data exists with the selection criteria'.

MESSAGE S002(ZLKPL_MSGCLASS) WITH LV_MESG.

V_FLAG = 'X'.

ENDIF.

ENDFORM. " SELECT_PO_DATA

&----


*& Form SELECT_PO_ITEM_DATA

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM SELECT_PO_ITEM_DATA.

*--- Select construct to get the PO Items

IF NOT IT_EKKO[] IS INITIAL.

SELECT A~EBELN

A~EBELP

A~PSTYP

A~MATNR

A~WERKS

B~MAKTX

A~MENGE

A~MEINS

A~BPRME

A~NETPR

A~PEINH

A~BANFN

A~BNFPO

INTO CORRESPONDING FIELDS OF TABLE IT_EKPO

FROM EKPO AS A

INNER JOIN MAKT AS B

ON AMATNR EQ BMATNR

FOR ALL ENTRIES IN IT_EKKO

WHERE A~EBELN = IT_EKKO-EBELN AND

B~SPRAS = 'E' .

IF SY-SUBRC = 0.

SORT IT_EKPO BY EBELN EBELP.

ENDIF.

ENDIF.

LOOP AT IT_EKPO.

AT NEW EBELN.

READ TABLE IT_EKKO WITH KEY EBELN = IT_EKPO-EBELN.

IT_FINAL1-FIELD1 = 'Purc Docu NO'.

IT_FINAL1-FIELD2 = 'Company Code'.

IT_FINAL1-FIELD3 = 'Purchasing Document Category'.

IT_FINAL1-FIELD4 = 'Purchasing Document Type'.

IT_FINAL1-FIELD5 = 'Status of purchasing document'.

IT_FINAL1-FIELD6 = 'Date on which the record was created'.

IT_FINAL1-FIELD7 = 'Terms of payment key'.

IT_FINAL1-FIELD8 = 'Purchasing Organization'.

IT_FINAL1-FIELD9 = 'Purchasing group'.

IT_FINAL1-FIELD10 = 'Currency Key'.

IT_FINAL1-FIELD11 = 'Purchasing document date'.

IT_FINAL1-FIELD12 = 'Vendors account number'.

IT_FINAL1-FIELD13 = 'Vendor Name'.

IT_FINAL1-FIELD14 = 'City'.

IT_FINAL1-FIELD15 = 'District'.

IT_FINAL1-FIELD16 = 'Postal Code'.

IT_FINAL1-FIELD17 = 'Region'.

IT_FINAL1-FIELD18 = 'House number and street'.

IT_FINAL1-FIELD19 = 'Address'.

APPEND IT_FINAL1.

CLEAR IT_FINAL1.

IT_FINAL1-FIELD1 = IT_EKKO-EBELN.

IT_FINAL1-FIELD2 = IT_EKKO-BUKRS.

IT_FINAL1-FIELD3 = IT_EKKO-BSTYP.

IT_FINAL1-FIELD4 = IT_EKKO-BSART.

IT_FINAL1-FIELD5 = IT_EKKO-STATU.

IT_FINAL1-FIELD6 = IT_EKKO-AEDAT.

IT_FINAL1-FIELD7 = IT_EKKO-ZTERM.

IT_FINAL1-FIELD8 = IT_EKKO-EKORG.

IT_FINAL1-FIELD9 = IT_EKKO-EKGRP.

IT_FINAL1-FIELD10 = IT_EKKO-WAERS.

IT_FINAL1-FIELD11 = IT_EKKO-BEDAT.

IT_FINAL1-FIELD12 = IT_EKKO-LIFNR.

IT_FINAL1-FIELD13 = IT_EKKO-NAME1.

IT_FINAL1-FIELD14 = IT_EKKO-ORT01.

IT_FINAL1-FIELD15 = IT_EKKO-ORT02.

IT_FINAL1-FIELD16 = IT_EKKO-PSTLZ.

IT_FINAL1-FIELD17 = IT_EKKO-REGIO.

IT_FINAL1-FIELD18 = IT_EKKO-STRAS.

IT_FINAL1-FIELD19 = IT_EKKO-ADRNR.

APPEND IT_FINAL1.

CLEAR IT_FINAL1.

IT_FINAL1-FIELD1 = 'Item Number of Purchasing Document'.

IT_FINAL1-FIELD2 = 'Item category in purchasing document'.

IT_FINAL1-FIELD3 = 'Material Number'.

IT_FINAL1-FIELD4 = 'Currency Key'.

IT_FINAL1-FIELD5 = 'Material Description'.

IT_FINAL1-FIELD6 = 'Purchase order quantity'.

IT_FINAL1-FIELD7 = 'Order unit'.

IT_FINAL1-FIELD8 = 'Order price unit (purchasing)'.

IT_FINAL1-FIELD9 = 'Net price in purchasing document '.

IT_FINAL1-FIELD10 = 'Price unit'.

IT_FINAL1-FIELD11 = 'Purchase requisition number'.

IT_FINAL1-FIELD12 = 'Item number of purchase requisition'.

APPEND IT_FINAL1.

CLEAR IT_FINAL1.

ENDAT.

IT_FINAL1-FIELD1 = IT_EKPO-EBELP.

IT_FINAL1-FIELD2 = IT_EKPO-PSTYP.

IT_FINAL1-FIELD3 = IT_EKPO-MATNR.

IT_FINAL1-FIELD4 = IT_EKPO-WERKS.

IT_FINAL1-FIELD5 = IT_EKPO-MAKTX.

IT_FINAL1-FIELD6 = IT_EKPO-MENGE.

IT_FINAL1-FIELD7 = IT_EKPO-MEINS.

IT_FINAL1-FIELD8 = IT_EKPO-BPRME.

IT_FINAL1-FIELD9 = IT_EKPO-NETPR.

IT_FINAL1-FIELD10 = IT_EKPO-PEINH.

IT_FINAL1-FIELD11 = IT_EKPO-BANFN.

IT_FINAL1-FIELD12 = IT_EKPO-BNFPO.

APPEND IT_FINAL1.

CLEAR IT_FINAL1.

ENDLOOP.

ENDFORM. " SELECT_PO_ITEM_DATA

&----


*& Form DOWNLOAD

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM DOWNLOAD.

<b> CALL FUNCTION 'GUI_DOWNLOAD'</b> EXPORTING

  • BIN_FILESIZE =

FILENAME = 'C:\PO_DOWNLOAD123.XLS'

FILETYPE = 'DAT'

  • APPEND = ' '

  • WRITE_FIELD_SEPARATOR = ' '

  • HEADER = IT_FINAL

  • TRUNC_TRAILING_BLANKS = ' '

  • WRITE_LF = 'X'

  • COL_SELECT = ' '

  • COL_SELECT_MASK = ' '

  • IMPORTING

  • FILELENGTH =

TABLES

DATA_TAB = IT_FINAL1

EXCEPTIONS

FILE_WRITE_ERROR = 1

NO_BATCH = 2

GUI_REFUSE_FILETRANSFER = 3

INVALID_TYPE = 4

NO_AUTHORITY = 5

UNKNOWN_ERROR = 6

HEADER_NOT_ALLOWED = 7

SEPARATOR_NOT_ALLOWED = 8

FILESIZE_NOT_ALLOWED = 9

HEADER_TOO_LONG = 10

DP_ERROR_CREATE = 11

DP_ERROR_SEND = 12

DP_ERROR_WRITE = 13

UNKNOWN_DP_ERROR = 14

ACCESS_DENIED = 15

DP_OUT_OF_MEMORY = 16

DISK_FULL = 17

DP_TIMEOUT = 18

FILE_NOT_FOUND = 19

DATAPROVIDER_EXCEPTION = 20

CONTROL_FLUSH_ERROR = 21

OTHERS = 22

.

IF SY-SUBRC <> 0.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

ENDFORM. " DOWNLOAD

Thanks

Vikranth Khimavath

Former Member
0 Kudos

Hi,

Sample code for Download.

&----


*

*& Report ZS_BDCDOWNLOAD *

*& *

&----


*& *

*& *

&----


REPORT ZS_BDCDOWNLOAD .

tables : zttab.

data : begin of itab occurs 0,

empid like zttab-empid,

empname like zttab-empname,

empdP like zttab-EMPDP,

end of itab.

selection-screen: begin of block b1 with frame title text-001.

parameter: p_file type rlgrap-filename default 'C:/BDC2.txt'

obligatory.

selection-screen: end of block b1.

*at selection-screen on value-request for p_file.

start-of-selection.

perform extract_data.

perform download_file using p_file.

end-of-selection.

&----


*& Form extract_data

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


form extract_data .

select empid

empname

empdP

into table itab

from zttab.

endform. " extract_data

&----


*& Form download_file

&----


  • text

----


  • -->P_P_FILE text

----


form download_file using p_p_file.

CALL FUNCTION 'WS_DOWNLOAD'

EXPORTING

  • BIN_FILESIZE = ' '

  • CODEPAGE = ' '

FILENAME = P_P_FILE

FILETYPE = 'ASC'

  • MODE = ' '

  • WK1_N_FORMAT = ' '

  • WK1_N_SIZE = ' '

  • WK1_T_FORMAT = ' '

  • WK1_T_SIZE = ' '

  • COL_SELECT = ' '

  • COL_SELECTMASK = ' '

  • NO_AUTH_CHECK = ' '

  • IMPORTING

  • FILELENGTH =

TABLES

data_tab = ITAB

  • FIELDNAMES =

EXCEPTIONS

FILE_OPEN_ERROR = 1

FILE_WRITE_ERROR = 2

INVALID_FILESIZE = 3

INVALID_TYPE = 4

NO_BATCH = 5

UNKNOWN_ERROR = 6

INVALID_TABLE_WIDTH = 7

GUI_REFUSE_FILETRANSFER = 8

CUSTOMER_ERROR = 9

NO_AUTHORITY = 10

OTHERS = 11.

IF sy-subrc <> 0.

MESSAGE E001(ZZ).

ENDIF.

endform. " download_file

Thanks

Sunil