‎2021 Sep 27 6:47 PM
Hi,
I'm currently working on saving my internal table to a local excel file.
Assume my internal table is 'IT_FINAL' and here are the codes.
DATA: GT_FIELDS TYPE TABLE OF STRING,
GS_FIELDS TYPE STRING.
DATA: FILENAME TYPE STRING,
PATH TYPE STRING,
FULLPATH TYPE STRING.
*header variables
GS_FIELDS = 'a, b, c, d, e, f, g, h, i, j'.
APPEND GS_FIELDS TO GT_FIELDS.
CALL METHOD CL_GUI_FRONTEND_SERVICES=>FILE_SAVE_DIALOG
EXPORTING
WINDOW_TITLE = 'Save'
FILE_FILTER = 'EXCEL FILES (*.XLS)|*.XLS|EXCEL FILES (*.XLSX)|*.XLSX|'
INITIAL_DIRECTORY = 'C:\'
CHANGING
FILENAME = FILENAME
PATH = PATH
FULLPATH = FULLPATH.
* Download to Excel
CALL METHOD CL_GUI_FRONTEND_SERVICES=>GUI_DOWNLOAD
EXPORTING
FILENAME = FULLPATH
WRITE_FIELD_SEPARATOR = ABAP_TRUE
APPEND = 'X'
FIELDNAMES = GT_FIELDS
CHANGING
DATA_TAB = IT_FINAL
EXCEPTIONS
OTHERS = 1.
I believe this should work fine, but I got a blank excel sheet somehow. I've tried SAP_CONVERT_TO_XLS_FORMAT FM as well, but all these don't seem to work for me. Any suggestion would be appreciated.
Thanks.
‎2021 Sep 27 8:18 PM
There's a nice blogpost by jagdish.patil which explains how to do it using standard classes. I have reworked his example because it had issues on an older system.
Another option, if you need something fancier, is to use abap2xlsx.
‎2021 Sep 27 8:18 PM
There's a nice blogpost by jagdish.patil which explains how to do it using standard classes. I have reworked his example because it had issues on an older system.
Another option, if you need something fancier, is to use abap2xlsx.
‎2021 Sep 28 5:48 AM
There's no relationship between filtering the list of files which have the extension .XLS or .XLSX shown in the Windows dialog of FILE_SAVE_DIALOG and creating an Excel file in format XLS or XLSX.
Concerning the method GUI_DOWNLOAD, the parameter FIELDNAMES doesn't exist.
GUI_DOWNLOAD can only download an internal table if you indicate a specific FILETYPE value like 'DAT' and the internal table will be written to a text file with tab-separated fields (that Excel displays in columns). Concerning your code, GUI_DOWNLOAD probably returns an exception, but you can't know which one if you only indicate OTHERS (alone, it intercepts all without knowing which one happens).
I advise to search the Web for examples how to create an XLSX file (abap2xlsx, ALV utility classes, etc.)