Req:How to set headings in XL sheet
Hi gurus,
when we are downloading the internal table into XL sheet how to put headings in the top of Excel sheet from the program itself.
Tags:
Abhijeet Kulshreshtha replied
Hi,
Check this sample code. I've called FM GUI_DOWNLOAD twice. Once to download the heading of internal table data. and another time to download internal table data itself. While downloading data of internal table make sure path for your heading and data is same and second time APPEND parameter of function module should be active.
APPEND = 'X'.
REPORT z_file_download. DATA: w_name(90) TYPE c. DATA: BEGIN OF fs_flight, carrid LIKE sflight-carrid, connid LIKE sflight-connid, fldate LIKE sflight-fldate, price LIKE sflight-price, currency LIKE sflight-currency, END OF fs_flight. DATA: BEGIN OF fs_head, carrid(10) TYPE c, connid(10) TYPE c, fldate(10) TYPE c, price(10) TYPE c, curr(10) TYPE c, END OF fs_head. DATA: t_head LIKE TABLE OF fs_head. DATA: t_flight LIKE TABLE OF fs_flight. fs_head-carrid = 'CARRID'. fs_head-connid = 'CONNID'. fs_head-fldate = 'FLDATE'. fs_head-price = 'PRICE'. fs_head-curr = 'CURRENCY'. APPEND fs_head TO t_head. SELECT-OPTIONS: s_carrid FOR fs_flight-carrid. START-OF-SELECTION. SELECT carrid connid fldate price currency FROM sflight INTO TABLE t_flight WHERE carrid IN s_carrid. CALL FUNCTION 'GUI_DOWNLOAD' EXPORTING * BIN_FILESIZE = filename = 'D:\flight.xls' FILETYPE = 'ASC' * APPEND = ' ' WRITE_FIELD_SEPARATOR = 'X' * HEADER = '00' * TRUNC_TRAILING_BLANKS = ' ' * WRITE_LF = 'X' * COL_SELECT = ' ' * COL_SELECT_MASK = ' ' * DAT_MODE = ' ' * CONFIRM_OVERWRITE = ' ' * NO_AUTH_CHECK = ' ' * CODEPAGE = ' ' * IGNORE_CERR = ABAP_TRUE * REPLACEMENT = '#' * WRITE_BOM = ' ' * IMPORTING * FILELENGTH = tables data_tab = t_head 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 NE 0. * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO * WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. ENDIF. CALL FUNCTION 'GUI_DOWNLOAD' EXPORTING filename = 'D:\flight.xls' filetype = 'ASC' append = 'X' write_field_separator = 'X' TABLES data_tab = t_flight 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 EQ 0. MESSAGE 'Download successful' TYPE 'I'. ELSE. * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO * WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. ENDIF.
Regards
Abhijeet