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: 

excel spread sheet

Former Member
0 Kudos

Hi All,

I am trying to add option my report that will allow me tio download information into a excel spreadsheet..please help guys as i need this urgently so and i will immediately reward point to all useful answers..

Thank you,

Fred.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi,

please do have a look at the following blog:

/people/dennis.vandenbroek/blog/2007/02/14/simple-function-module-to-export-any-internal-table-to-ms-excel

i think it may be useful to you.

Regards

Sudheer

9 REPLIES 9

Former Member
0 Kudos

Hi,

please do have a look at the following blog:

/people/dennis.vandenbroek/blog/2007/02/14/simple-function-module-to-export-any-internal-table-to-ms-excel

i think it may be useful to you.

Regards

Sudheer

Former Member
0 Kudos

Hi,

you can use the function module

gui_download

which is used to download the data into an excel sheet

data: filename type string.

take the filename path from selection screen and pass it to here

better to take the existing blank excel sheet..

thanks & regards,

Venkatesh

Former Member
0 Kudos

Hi Fred,

I did this thing. In this Code you have to set PF Status in which you are required to create Button with Name Process with any text.

&----


*& Report ZSB_AP_GARNISH_ALV_SEC_LIST

*&

&----


REPORT ZSB_AP_GARNISH_ALV_SEC_LIST MESSAGE-ID ZFIMESSAGE.

TYPE-POOLS: slis.

  • TABLES USED.

TABLES: bsik,bseg.

                          • User defined Types *************

TYPES: BEGIN OF st_bsik,

bukrs TYPE bsik-bukrs,

lifnr TYPE bsik-lifnr,

belnr TYPE bsik-belnr,

wrbtr TYPE bsik-wrbtr,

shkzg TYPE bsik-shkzg,

waers TYPE bsik-waers,

budat TYPE bsik-budat,

gjahr TYPE bsik-gjahr,

END OF st_bsik.

TYPES: BEGIN OF st_temp,

hkont TYPE bseg-hkont,

lifnr TYPE bsik-lifnr,

belnr TYPE bsik-belnr,

bukrs TYPE bsik-bukrs,

waers TYPE bsik-waers,

budat TYPE bsik-budat,

gjahr TYPE bsik-gjahr,

wrbtr TYPE bseg-wrbtr,

shkzg TYPE bsik-shkzg,

END OF st_temp.

******************************************

DATA: it_bsik TYPE STANDARD TABLE OF st_bsik INITIAL SIZE 0,

it_bsik_wa TYPE st_bsik,

it_temp TYPE STANDARD TABLE OF st_temp,

it_temp_wa TYPE st_temp. "WITH HEADER LINE.

*ALV data declarations

DATA: i_fcat TYPE slis_t_fieldcat_alv,

wa_fcat TYPE slis_fieldcat_alv,

gd_tab_group TYPE slis_t_sp_group_alv,

gd_layout TYPE slis_layout_alv.

  • Selection Screen *****************************

SELECTION-SCREEN BEGIN OF BLOCK bl_bsik WITH FRAME TITLE title.

SELECT-OPTIONS ccode FOR bsik-bukrs default '1000'.

SELECT-OPTIONS vno FOR bsik-lifnr default '1000'.

SELECT-OPTIONS yod FOR bsik-gjahr default 2007.

SELECTION-SCREEN END OF BLOCK bl_bsik.

*End of Selection Screen **********************

                                                  • Start of Selection *****************

START-OF-SELECTION.

PERFORM firstlist.

&----


*& Form FIRSTLIST

&----


FORM firstlist.

  • GET DATA INTO ITAB FROM DB.

SELECT bukrs lifnr wrbtr shkzg waers belnr budat gjahr

FROM bsik

INTO CORRESPONDING FIELDS OF TABLE it_bsik

WHERE bukrs IN ccode

AND lifnr IN vno

AND gjahr IN yod.

*SELECT BUKRS

  • GJAHR HKONT BELNR WRBTR SHKZG FROM BSEG

  • INTO CORRESPONDING FIELDS OF TABLE it_temp

  • FOR ALL ENTRIES IN it_bsik

  • WHERE BELNR = it_bsik_wa-belnr

  • AND BUKRS = it_bsik-BUKRS

  • AND GJAHR = it_bsik-GJAHR

  • AND KOART <> 'K'.

loop at it_bsik into it_bsik_wa.

SELECT BUKRS GJAHR HKONT BELNR WRBTR SHKZG FROM BSEG

into corresponding fields of bseg

WHERE BELNR = it_bsik_wa-BELNR

AND BUKRS = it_bsik_wa-BUKRS

AND GJAHR = it_bsik_wa-GJAHR

AND KOART <> 'K'.

if sy-subrc <> 0.

exit.

else.

  • loop at it_temp into it_temp_wa.

MOVE bseg-HKONT to it_temp_wa-HKONT.

MOVE bseg-WRBTR to it_temp_wa-WRBTR.

MOVE it_bsik_wa-BUDAT to it_temp_wa-BUDAT.

MOVE it_bsik_wa-SHKZG to it_temp_wa-SHKZG.

MOVE it_bsik_wa-LIFNR to it_temp_wa-LIFNR.

MOVE it_bsik_wa-BELNR to it_temp_wa-BELNR.

MOVE it_bsik_wa-GJAHR to it_temp_wa-GJAHR.

MOVE it_bsik_wa-WAERS to it_temp_wa-WAERS.

APPEND it_temp_wa to it_temp.

  • endloop.

endif.

ENDSELECT.

ENDLOOP.

DATA: ls_fieldcat TYPE slis_fieldcat_alv,

lt_fieldcat TYPE slis_t_fieldcat_alv with header line,

ls_layout TYPE slis_layout_alv,

lt_sort TYPE slis_t_sortinfo_alv,

ls_sort TYPE slis_sortinfo_alv.

lt_fieldcat-ref_tabname = 'it_bsik'.

  • lt_fieldcat-ref_fieldname = 'BUKRS'.

ls_layout-zebra = 'X'.

ls_layout-cell_merge = 'X'.

  • **** SORT ****

ls_sort-fieldname = 'LIFNR'.

ls_sort-up = 'X'.

ls_sort-subtot = 'X'.

APPEND ls_sort TO lt_sort.

CLEAR ls_sort.

ls_sort-up = 'X'.

ls_sort-fieldname = 'GJAHR'.

APPEND ls_sort TO lt_sort.

CLEAR ls_sort.

ls_sort-fieldname = 'BUDAT'.

ls_sort-up = 'X'.

APPEND ls_sort TO lt_sort.

CLEAR ls_sort.

ls_sort-up = 'X'.

ls_sort-fieldname = 'BELNR'.

ls_sort-subtot = ''.

APPEND ls_sort TO lt_sort.

CLEAR ls_sort.

  • ls_fieldcat-tabname = 'IT_TEMP'.

  • ls_fieldcat-col_pos = '1'.

  • ls_fieldcat-seltext_l = 'Company Code'.

  • ls_fieldcat-outputlen = 20.

  • ls_fieldcat-fieldname = 'BUKRS'.

  • APPEND ls_fieldcat TO lt_fieldcat.

  • CLEAR ls_fieldcat.

ls_fieldcat-tabname = 'IT_TEMP'.

ls_fieldcat-col_pos = '1'.

ls_fieldcat-outputlen = 20.

ls_fieldcat-seltext_l = 'Document No'.

ls_fieldcat-fieldname = 'BELNR'.

APPEND ls_fieldcat TO lt_fieldcat.

CLEAR ls_fieldcat.

ls_fieldcat-tabname = 'IT_TEMP'.

ls_fieldcat-col_pos = '2'.

ls_fieldcat-seltext_l = 'Document Date'.

ls_fieldcat-outputlen = 10.

ls_fieldcat-fieldname = 'BUDAT'.

APPEND ls_fieldcat TO lt_fieldcat.

CLEAR ls_fieldcat.

ls_fieldcat-tabname = 'IT_TEMP'.

ls_fieldcat-col_pos = '3'.

ls_fieldcat-seltext_l = 'Year'.

ls_fieldcat-fieldname = 'GJAHR'.

APPEND ls_fieldcat TO lt_fieldcat.

CLEAR ls_fieldcat.

ls_fieldcat-tabname = 'IT_TEMP'.

ls_fieldcat-col_pos = '4'.

ls_fieldcat-seltext_l = 'Vendor Code'.

ls_fieldcat-fieldname = 'LIFNR'.

APPEND ls_fieldcat TO lt_fieldcat.

CLEAR ls_fieldcat.

ls_fieldcat-tabname = 'IT_TEMP'.

ls_fieldcat-col_pos = '5'.

ls_fieldcat-seltext_l = 'G/L Account'.

ls_fieldcat-fieldname = 'HKONT'.

APPEND ls_fieldcat TO lt_fieldcat.

CLEAR ls_fieldcat.

ls_fieldcat-tabname = 'IT_TEMP'.

ls_fieldcat-col_pos = '6'.

ls_fieldcat-reptext_ddic = 'Amount'.

ls_fieldcat-fieldname = 'WRBTR'.

ls_fieldcat-do_sum = 'X'.

APPEND ls_fieldcat TO lt_fieldcat.

CLEAR ls_fieldcat.

ls_fieldcat-tabname = 'IT_TEMP'.

ls_fieldcat-col_pos = '7'.

ls_fieldcat-seltext_l = 'Currency Code'.

ls_fieldcat-outputlen = 10.

ls_fieldcat-fieldname = 'WAERS'.

APPEND ls_fieldcat TO lt_fieldcat.

CLEAR ls_fieldcat.

ls_fieldcat-tabname = 'IT_TEMP'.

ls_fieldcat-col_pos = '8'.

ls_fieldcat-seltext_l = 'Indicator'.

ls_fieldcat-fieldname = 'SHKZG'.

APPEND ls_fieldcat TO lt_fieldcat.

CLEAR ls_fieldcat.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

  • I_INTERFACE_CHECK = ' '

  • I_BYPASSING_BUFFER = ' '

  • I_BUFFER_ACTIVE = ' '

i_callback_program = sy-repid

I_CALLBACK_PF_STATUS_SET = 'SETSTATUS'

I_CALLBACK_USER_COMMAND = 'USRCMD'

  • I_CALLBACK_TOP_OF_PAGE = ' '

  • I_CALLBACK_HTML_TOP_OF_PAGE = ' '

  • I_CALLBACK_HTML_END_OF_LIST = ' '

  • I_STRUCTURE_NAME =

  • I_BACKGROUND_ID = ' '

  • I_GRID_TITLE =

  • I_GRID_SETTINGS =

IS_LAYOUT = ls_layout

it_fieldcat = lt_fieldcat[]

  • IT_EXCLUDING =

  • IT_SPECIAL_GROUPS =

IT_SORT = lt_sort

  • IT_FILTER =

  • IS_SEL_HIDE =

  • I_DEFAULT = 'X'

I_SAVE = 'A'

  • IS_VARIANT =

  • IT_EVENTS =

  • IT_EVENT_EXIT =

  • IS_PRINT =

  • IS_REPREP_ID =

  • I_SCREEN_START_COLUMN = 0

  • I_SCREEN_START_LINE = 0

  • I_SCREEN_END_COLUMN = 0

  • I_SCREEN_END_LINE = 0

  • I_HTML_HEIGHT_TOP = 0

  • I_HTML_HEIGHT_END = 0

  • IT_ALV_GRAPHICS =

  • IT_HYPERLINK =

  • IT_ADD_FIELDCAT =

  • IT_EXCEPT_QINFO =

  • IR_SALV_FULLSCREEN_ADAPTER =

  • IMPORTING

  • E_EXIT_CAUSED_BY_CALLER =

  • ES_EXIT_CAUSED_BY_USER =

TABLES

t_outtab = it_temp[]

  • EXCEPTIONS

  • PROGRAM_ERROR = 1

  • OTHERS = 2

.

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

&----


*& Form SETSTATUS

&----


  • text

----


  • -->RT_EXTAB text

----


FORM setstatus USING rt_extab TYPE slis_t_extab.

SET PF-STATUS 'APPTOOLBAR'.

ENDFORM. "SETSTATUS

FORM usrcmd USING r_ucomm LIKE sy-ucomm

rs_selfield TYPE slis_selfield.

CASE r_ucomm.

WHEN 'SAVE'.

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

  • BIN_FILESIZE =

filename = 'C:\GARNISHMENT_AP.XLS'

FILETYPE = 'DBF'

  • APPEND = ' '

  • WRITE_FIELD_SEPARATOR = ' '

  • HEADER = '00'

  • TRUNC_TRAILING_BLANKS = ' '

  • WRITE_LF = 'X'

  • COL_SELECT = ' '

  • COL_SELECT_MASK = ' '

  • DAT_MODE = ' '

CONFIRM_OVERWRITE = 'X'

  • NO_AUTH_CHECK = ' '

  • CODEPAGE = ' '

  • IGNORE_CERR = ABAP_TRUE

  • REPLACEMENT = '#'

  • WRITE_BOM = ' '

  • TRUNC_TRAILING_BLANKS_EOL = 'X'

  • WK1_N_FORMAT = ' '

  • WK1_N_SIZE = ' '

  • WK1_T_FORMAT = ' '

  • WK1_T_SIZE = ' '

  • IMPORTING

  • FILELENGTH =

tables

data_tab = it_temp[]

  • FIELDNAMES =

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.

ELSE.

MESSAGE E004 WITH 'IN C:\GARNISHMENT_AP.XLS'.

ENDIF.

ENDCASE.

ENDFORM.

For Any help Reply me.

Reward if useful

Sachin.

Former Member
0 Kudos

Hi,

Function module 'WS_DOWNLOAD' is uesed to downlaod into excel format.

find the below example for your reference.

*Download in presentation server

tables ZDEPARTMENT_INF1.

data : a1 like ZDEPARTMENT_INF1 occurs 10 with header line.

select * from ZDEPARTMENT_INF1 into table a1.

CALL FUNCTION 'WS_DOWNLOAD'

EXPORTING

  • BIN_FILESIZE = ' '

  • CODEPAGE = ' '

FILENAME = 'D:\YHDEPT1.xls'

FILETYPE = 'DAT'

  • 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 = a1

  • 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

  • OTHERS = 10

.

IF sy-subrc <> 0.

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

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

ENDIF.

Reward points!!

Thanks & Regards,

Vasudeva Rao

Former Member
0 Kudos

Download a report to excel with format (border, color cell, etc)

Try this program...it may help you to change the font ..etc.

Code:

REPORT ZSIRI NO STANDARD PAGE HEADING.

  • this report demonstrates how to send some ABAP data to an

  • EXCEL sheet using OLE automation.

INCLUDE OLE2INCL.

  • handles for OLE objects

DATA: H_EXCEL TYPE OLE2_OBJECT, " Excel object

H_MAPL TYPE OLE2_OBJECT, " list of workbooks

H_MAP TYPE OLE2_OBJECT, " workbook

H_ZL TYPE OLE2_OBJECT, " cell

H_F TYPE OLE2_OBJECT. " font

TABLES: SPFLI.

DATA H TYPE I.

  • table of flights

DATA: IT_SPFLI LIKE SPFLI OCCURS 10 WITH HEADER LINE.

&----


*& Event START-OF-SELECTION

&----


START-OF-SELECTION.

  • read flights

SELECT * FROM SPFLI INTO TABLE IT_SPFLI UP TO 10 ROWS.

  • display header

ULINE (61).

WRITE: / SY-VLINE NO-GAP,

(3) 'Flg'(001) COLOR COL_HEADING NO-GAP, SY-VLINE NO-GAP,

(4) 'Nr'(002) COLOR COL_HEADING NO-GAP, SY-VLINE NO-GAP,

(20) 'Von'(003) COLOR COL_HEADING NO-GAP, SY-VLINE NO-GAP,

(20) 'Nach'(004) COLOR COL_HEADING NO-GAP, SY-VLINE NO-GAP,

(8) 'Zeit'(005) COLOR COL_HEADING NO-GAP, SY-VLINE NO-GAP.

ULINE /(61).

  • display flights

LOOP AT IT_SPFLI.

WRITE: / SY-VLINE NO-GAP,

IT_SPFLI-CARRID COLOR COL_KEY NO-GAP, SY-VLINE NO-GAP,

IT_SPFLI-CONNID COLOR COL_NORMAL NO-GAP, SY-VLINE NO-GAP,

IT_SPFLI-CITYFROM COLOR COL_NORMAL NO-GAP, SY-VLINE NO-GAP,

IT_SPFLI-CITYTO COLOR COL_NORMAL NO-GAP, SY-VLINE NO-GAP,

IT_SPFLI-DEPTIME COLOR COL_NORMAL NO-GAP, SY-VLINE NO-GAP.

ENDLOOP.

ULINE /(61).

  • tell user what is going on

CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'

EXPORTING

  • PERCENTAGE = 0

TEXT = TEXT-007

EXCEPTIONS

OTHERS = 1.

  • start Excel

CREATE OBJECT H_EXCEL 'EXCEL.APPLICATION'.

  • PERFORM ERR_HDL.

SET PROPERTY OF H_EXCEL 'Visible' = 1.

  • CALL METHOD OF H_EXCEL 'FILESAVEAS' EXPORTING #1 = 'c:\kis_excel.xls'

.

  • PERFORM ERR_HDL.

  • tell user what is going on

CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'

EXPORTING

  • PERCENTAGE = 0

TEXT = TEXT-008

EXCEPTIONS

OTHERS = 1.

  • get list of workbooks, initially empty

CALL METHOD OF H_EXCEL 'Workbooks' = H_MAPL.

PERFORM ERR_HDL.

  • add a new workbook

CALL METHOD OF H_MAPL 'Add' = H_MAP.

PERFORM ERR_HDL.

  • tell user what is going on

CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'

EXPORTING

  • PERCENTAGE = 0

TEXT = TEXT-009

EXCEPTIONS

OTHERS = 1.

  • output column headings to active Excel sheet

PERFORM FILL_CELL USING 1 1 1 'Flug'(001).

PERFORM FILL_CELL USING 1 2 0 'Nr'(002).

PERFORM FILL_CELL USING 1 3 1 'Von'(003).

PERFORM FILL_CELL USING 1 4 1 'Nach'(004).

PERFORM FILL_CELL USING 1 5 1 'Zeit'(005).

LOOP AT IT_SPFLI.

  • copy flights to active EXCEL sheet

H = SY-TABIX + 1.

PERFORM FILL_CELL USING H 1 0 IT_SPFLI-CARRID.

PERFORM FILL_CELL USING H 2 0 IT_SPFLI-CONNID.

PERFORM FILL_CELL USING H 3 0 IT_SPFLI-CITYFROM.

PERFORM FILL_CELL USING H 4 0 IT_SPFLI-CITYTO.

PERFORM FILL_CELL USING H 5 0 IT_SPFLI-DEPTIME.

ENDLOOP.

  • changes by Kishore - start

  • CALL METHOD OF H_EXCEL 'Workbooks' = H_MAPL.

CALL METHOD OF H_EXCEL 'Worksheets' = H_MAPL." EXPORTING #1 = 2.

PERFORM ERR_HDL.

  • add a new workbook

CALL METHOD OF H_MAPL 'Add' = H_MAP EXPORTING #1 = 2.

PERFORM ERR_HDL.

  • tell user what is going on

SET PROPERTY OF H_MAP 'NAME' = 'COPY'.

CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'

EXPORTING

  • PERCENTAGE = 0

TEXT = TEXT-009

EXCEPTIONS

OTHERS = 1.

  • output column headings to active Excel sheet

PERFORM FILL_CELL USING 1 1 1 'Flug'(001).

PERFORM FILL_CELL USING 1 2 0 'Nr'(002).

PERFORM FILL_CELL USING 1 3 1 'Von'(003).

PERFORM FILL_CELL USING 1 4 1 'Nach'(004).

PERFORM FILL_CELL USING 1 5 1 'Zeit'(005).

LOOP AT IT_SPFLI.

  • copy flights to active EXCEL sheet

H = SY-TABIX + 1.

PERFORM FILL_CELL USING H 1 0 IT_SPFLI-CARRID.

PERFORM FILL_CELL USING H 2 0 IT_SPFLI-CONNID.

PERFORM FILL_CELL USING H 3 0 IT_SPFLI-CITYFROM.

PERFORM FILL_CELL USING H 4 0 IT_SPFLI-CITYTO.

PERFORM FILL_CELL USING H 5 0 IT_SPFLI-DEPTIME.

ENDLOOP.

  • changes by Kishore - end

  • disconnect from Excel

  • CALL METHOD OF H_EXCEL 'FILESAVEAS' EXPORTING #1 = 'C:\SKV.XLS'.

FREE OBJECT H_EXCEL.

PERFORM ERR_HDL.

----


  • FORM FILL_CELL *

----


  • sets cell at coordinates i,j to value val boldtype bold *

----


FORM FILL_CELL USING I J BOLD VAL.

CALL METHOD OF H_EXCEL 'Cells' = H_ZL EXPORTING #1 = I #2 = J.

PERFORM ERR_HDL.

SET PROPERTY OF H_ZL 'Value' = VAL .

PERFORM ERR_HDL.

GET PROPERTY OF H_ZL 'Font' = H_F.

PERFORM ERR_HDL.

SET PROPERTY OF H_F 'Bold' = BOLD .

PERFORM ERR_HDL.

ENDFORM.

&----


*& Form ERR_HDL

&----


  • outputs OLE error if any *

----


  • --> p1 text

  • <-- p2 text

----


FORM ERR_HDL.

IF SY-SUBRC <> 0.

WRITE: / 'Fehler bei OLE-Automation:'(010), SY-SUBRC.

STOP.

ENDIF.

ENDFORM. " ERR_HDL

Former Member
0 Kudos

hi check this..

PARAMETERS: p_file LIKE rlgrap-filename.

DATA: t100_Lines TYPE STANDARD TABLE OF t001.

SELECT * FROM t001 INTO TABLE t100_Lines.

CALL FUNCTION 'SAP_CONVERT_TO_XLS_FORMAT'

EXPORTING

i_filename = p_file

TABLES

i_tab_sap_data = t100_Lines.

u can add this msg to know whether file is created or not..

IF SY-SUBRC <> 0.

MESSAGE I000(BCTRAIN) WITH 'File not transfered' SY-MSGID.

ELSE.

MESSAGE I000(BCTRAIN) WITH 'File transfered'.

ENDIF.

Message was edited by:

Premalatha G

0 Kudos

Hi Premalatha,

When i execute nothing is happening..

Please help me again

Fred.

0 Kudos

hi

after execution an excel file will b created with the data in the path given by u in the parameter.

Former Member
0 Kudos

Hi,

Try using this code for downloading.

PARAMETERS : p_dsn TYPE rlgrap-filename.

data: p_dsn1 type string.

DATA: BEGIN OF gt_mara OCCURS 0,

matnr TYPE mara-matnr,

ersda TYPE mara-ersda,

ernam TYPE mara-ernam,

mtart TYPE mara-mtart,

END OF gt_mara.

DATA: BEGIN OF gt_marc OCCURS 0,

matnr TYPE marc-matnr,

werks TYPE marc-werks,

pstat TYPE marc-pstat,

END OF gt_marc.

DATA: BEGIN OF gt_final OCCURS 0,

matnr(18) TYPE c,

ersda(10) TYPE c,

ernam TYPE mara-ernam,

mtart TYPE mara-mtart,

werks TYPE marc-werks,

pstat TYPE marc-pstat,

END OF gt_final.

START-OF-SELECTION.

SELECT matnr ersda ernam mtart

FROM mara

INTO TABLE gt_mara.

SELECT matnr werks pstat

INTO TABLE gt_marc

FROM marc.

LOOP AT gt_mara.

LOOP AT gt_marc WHERE matnr = gt_mara-matnr.

MOVE gt_mara TO gt_final.

MOVE gt_marc TO gt_final.

APPEND gt_final.

CLEAR gt_final.

ENDLOOP.

ENDLOOP.

p_dsn1 = p_dsn.

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

  • BIN_FILESIZE =

filename = P_DSN1

FILETYPE = 'ASC'

    • APPEND = ' '

    • WRITE_FIELD_SEPARATOR = ' '

    • HEADER = '00'

    • TRUNC_TRAILING_BLANKS = ' '

    • WRITE_LF = 'X'

    • COL_SELECT = ' '

    • COL_SELECT_MASK = ' '

    • DAT_MODE = ' '

    • IMPORTING

    • FILELENGTH =

tables

data_tab = GT_final.

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

Regards,

Hema.