Pages

Sunday, April 4, 2010

Download Internal Table to Excel with headers

lv_del = cl_abap_char_utilities=>horizontal_tab.

lv_file = p_file.

CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
* BIN_FILESIZE =
filename = lv_file
filetype = c_ftype_asc
* APPEND = ' '
write_field_separator = lv_del
* 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 = ' '
* trunc_trailing_blanks_eol =
* IMPORTING
* FILELENGTH =
TABLES
data_tab = p_table
fieldnames = p_heading
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 'I' NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ELSE.
MESSAGE i003 WITH 'File downloaded successfully:'(i04) lv_file.
ENDIF.
***********************************

Header Part.
We need to populate header data just like field catalog and pass the header details internal table to the Download FM above. Here we have passed P_HEADER which has been built in the following ways:

wa_header-fname = 'Reason'(r16).
APPEND wa_header TO p_header.
CLEAR wa_header.

wa_header-fname = 'ZPID'(r02).
APPEND wa_header TO p_header.
CLEAR wa_header.
*****************************

No comments:

Post a Comment