Documente Academic
Documente Profesional
Documente Cultură
(http://www.sap.com/)
(https://community.sap.com)
(/users/login.html?redirect_to=%2Fquestions%2F4315311%2Fdownload-
internal-table-to-excel-with-
header.html%3Fpage%3D2%26pageSize%3D10%26sort%3Dvotes)
Ask a Question (https://answers.sap.com/questions/ask.html) Write a Blog Post (https://blogs.sap.com/wp-admin/post-new.php) Login (/users
Former Member
Download internal table to excel with header
Jun 25, 2008 at 09:09 AM | 10.3k Views
ons%2F4315311%2Fdownload-internal-table-to-excel-with-
s_action%3DvoteUp%26s_data%3D4315311%26s_csrf%3D1582119582813.3555)
0
ons%2F4315311%2Fdownload-internal-table-to-excel-with-
_action%3DvoteDown%26s_data%3D4315311%26s_csrf%3D1582119582813.3555)
Hi All,
I have a requirement to download internal table contents to excel with field headings. I tried searching in forums before posting but didn't got much help.
I have used GUI_DOWNLOAD, WS_DOWNLOAD and EXCEL_OLE_STANDARD_DAT.
But unable to download the header in excel..along with data...
EXCEL_OLE_STANDARD_DAT is getting field header in excel but not downloading automatically , need to save manually which is not the requirement.
The data is huge with around 151 columns....I got 2 internal tables.
One for the data and the other with field names.
Many Thanks,
Ravi K
Follow (/users/login.html?redirect_to=%2Fquestions%2F4315311%2Fdownload-internal-table-to-excel-with-header.html%3Fpage%3D2%26pageSize%3D10%26sort%3Dvotes%26s_action%3Dfollow%26s_csrf%3D1582119582813.3555)
RSS Feed
Related questions
Header with multipal lines (https://answers.sap.com/questions/5564479/header-with-multipal-lines.html)
By Former Member ( https://people.sap.com/former.member) , Feb 25, 2009
problem with downloading itab header to excel sheet using ole concept (https://answers.sap.com/questions/4534650/problem-with-downloading-itab-header-to-excel-shee.html)
By Former Member ( https://people.sap.com/former.member) , Aug 03, 2008
12 Answers
Former Member
/
Feb 12, 2013 at 08:03 AM
Hi Ravi,
ct_to=%2Fquestions%2F4315311%2Fdownload-internal-table-to-excel-with-
pageSize%3D10%26sort%3Dvotes%26childToView%3D9825047%23answer-
DvoteUp%26s_data%3D9825047%26s_csrf%3D1582119582813.3555)
0 Load the internal table and pass it to the Function module GUI_DOWNLOAD
ct_to=%2Fquestions%2F4315311%2Fdownload-internal-table-to-excel-with-
pageSize%3D10%26sort%3Dvotes%26childToView%3D9825047%23answer-
voteDown%26s_data%3D9825047%26s_csrf%3D1582119582813.3555)
TYPES:begin of TY_ITEMS,
value1 type c,
value2 type i,
end of TY_ITEMS.
TYPES:begin of TY_HEADER,
TEXT(10) type c,
end of TY_HEADER.
DATA:IT_ITEMS type standard table of ty_items,
it_header type standard table of ty_header.
DATA: wa_items type ty_items,
wa_header type ty_header.
wa_items-value1 = 'X'.
wa_items-value2 = 100.
append wa_items to it_items.
wa_items-value1 = 'Z'.
wa_items-value2 = 200.
append wa_items to it_items.
wa_header-text = 'NAME'.
append wa_header to it_header.
wa_header-text = 'VALUE'.
append wa_header to it_header.
call function 'GUI_DOWNLOAD'
exporting
lename = 'C:\Users\acer\Desktop\backup\text.xls'
FILETYPE = 'DAT'
WRITE_FIELD_SEPARATOR = '#'
SHOW_TRANSFER_STATUS = 'X'
tables
data_tab = it_items
FIELDNAMES = it_header[]
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.
Share
Hi Ravi,
ct_to=%2Fquestions%2F4315311%2Fdownload-internal-table-to-excel-with-
DvoteUp%26s_data%3D10884244%26s_csrf%3D1582119582813.3555)
ageSize%3D10%26sort%3Dvotes%26childToView%3D10884244%23answer-
0 You need to have 2 di erent internal tables for achieving the needful. One internal table would be having your data and another would store your
ct_to=%2Fquestions%2F4315311%2Fdownload-internal-table-to-excel-with-
voteDown%26s_data%3D10884244%26s_csrf%3D1582119582813.3555)
ageSize%3D10%26sort%3Dvotes%26childToView%3D10884244%23answer-
table eld names i.e., declare a structure of length 100 characters,
TYPES : BEGIN OF GTY_FIELDNAMES,
TITLE(100),
END OF GTY_FIELDNAMES.
Now have a subroutine where by you append your headings into the internal table i.e.,GIT_FIELDNAMES
/
CLEAR GWA_FIELDNAMES.
GWA_FIELDNAMES-TITLE = 'Material Number'.
APPEND GWA_FIELDNAMES TO GIT_FIELDNAMES.
CLEAR GWA_FIELDNAMES.
GWA_FIELDNAMES-TITLE = 'Material Description'.
APPEND GWA_FIELDNAMES TO GIT_FIELDNAMES.
Once you are done with it you can call up the save dialog
* Display save dialog window
CALL METHOD CL_GUI_FRONTEND_SERVICES=>FILE_SAVE_DIALOG
EXPORTING
WINDOW_TITLE = 'Save File As...'
DEFAULT_EXTENSION = 'XLS'
DEFAULT_FILE_NAME = 'SalesPlan'
INITIAL_DIRECTORY = 'C:\'
CHANGING
FILENAME = GD_FILENAME
PATH = GD_PATH
FULLPATH = GD_FULLPATH
USER_ACTION = GD_RESULT.
Find us on