Sunteți pe pagina 1din 5

Community

(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

Not what you're looking for? Search community questions.

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

ABAP Development (/tags/833755570260738661924709785639136)

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

Votes | Newest | Oldest

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.

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

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


endif.

Share

Varun Kumar Sahu ( https://people.sap.com/varunkumar.sahu)


(/users/49929/varunkumarsahu.html)

May 05, 2014 at 05:08 AM

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.

DATA: GIT_FIELDNAMES TYPE STANDARD TABLE OF GTY_FIELDNAMES,


GWA_FIELDNAMES TYPE GTY_FIELDNAMES.

DATA : GD_FILENAME TYPE STRING,


GD_PATH TYPE STRING,
GD_FULLPATH TYPE STRING,
GD_RESULT TYPE I.

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.

* Check user did not cancel request


CHECK GD_RESULT EQ '0'.

CALL FUNCTION 'GUI_DOWNLOAD'


EXPORTING
FILENAME = GD_FULLPATH
FILETYPE = 'ASC'
* APPEND = 'X'
WRITE_FIELD_SEPARATOR = 'X'
* CONFIRM_OVERWRITE = 'X'
TABLES
DATA_TAB = GIT_FINAL " Internal table having data
FIELDNAMES = GIT_FIELDNAMES " Internal table having headings
EXCEPTIONS
FILE_OPEN_ERROR = 1 "#EC ARGCHECKED
FILE_WRITE_ERROR = 2
OTHERS = 3.

Hope this gets sorted your problem.


Thanks & Regards,
Varun Kumar Sahu
Share

Find us on

(https://www.facebook.com/sapcommunity) (https://twitter.com/SAPCommunity) (https://www.youtube.com/c/SAPCommunities) (https://www.linkedin.com/company/sap)


/
( ttps aceboo co sapco u ty) ( ttps t tte co S Co u ty) ( ttps youtube co c S Co u t es) ( ttps ed co co pa y sap)

(https://instagram.com/sap/) (http://www.slideshare.net/SAP) (mailto:?subject='SAP Community')

Privacy (http://sap.com/about/legal/privacy.html) Terms of Use (http://sap.com/corporate/en/legal/terms-of-use.html)

Legal Disclosure (http://sap.com/about/legal/impressum.html) Copyright (http://sap.com/about/legal/copyright.html)

Trademark (http://sap.com/about/legal/trademark.html) Cookie Preferences

Newsletter (https://www.sap.com/cmp/nl/sap-community-voice/index.html) Support (mailto:sapnetwork@sap.com)

S-ar putea să vă placă și