2008 Jul 18 4:00 PM
Hi,
Can any one help me with a function module or code to get the data in internal tabel to an excel sheet on desktop.
Thanks.
2008 Jul 18 4:04 PM
HI,
DATA: BEGIN OF ITAB OCCURS 0,
MATNR(10),
WERKS(4),
LGORT(4),
END OF ITAB.
************************************************************************
*THIS IS FOR UPLOAD *
************************************************************************
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename ='C:\docu.XLS'
FILETYPE = 'ASC'
HAS_FIELD_SEPARATOR = 'X'
HEADER_LENGTH = 0
READ_BY_LINE = 'X'
DAT_MODE = ' '
IMPORTING
FILELENGTH =
HEADER =
tables
data_tab = ITAB
EXCEPTIONS
FILE_OPEN_ERROR = 1
FILE_READ_ERROR = 2
NO_BATCH = 3
GUI_REFUSE_FILETRANSFER = 4
INVALID_TYPE = 5
NO_AUTHORITY = 6
UNKNOWN_ERROR = 7
BAD_DATA_FORMAT = 8
HEADER_NOT_ALLOWED = 9
SEPARATOR_NOT_ALLOWED = 10
HEADER_TOO_LONG = 11
UNKNOWN_DP_ERROR = 12
ACCESS_DENIED = 13
DP_OUT_OF_MEMORY = 14
DISK_FULL = 15
DP_TIMEOUT = 16
OTHERS = 17
.
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
loop at itab.
write : / itab-matnr, itab-werks, itab-LGORT.
endloop.
Points if helpfull
Hi,
Can any one help me with a function module or code to get the data in internal tabel to an excel sheet on desktop.
Thanks.
2008 Jul 18 4:04 PM
HI,
DATA: BEGIN OF ITAB OCCURS 0,
MATNR(10),
WERKS(4),
LGORT(4),
END OF ITAB.
************************************************************************
*THIS IS FOR UPLOAD *
************************************************************************
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename ='C:\docu.XLS'
FILETYPE = 'ASC'
HAS_FIELD_SEPARATOR = 'X'
HEADER_LENGTH = 0
READ_BY_LINE = 'X'
DAT_MODE = ' '
IMPORTING
FILELENGTH =
HEADER =
tables
data_tab = ITAB
EXCEPTIONS
FILE_OPEN_ERROR = 1
FILE_READ_ERROR = 2
NO_BATCH = 3
GUI_REFUSE_FILETRANSFER = 4
INVALID_TYPE = 5
NO_AUTHORITY = 6
UNKNOWN_ERROR = 7
BAD_DATA_FORMAT = 8
HEADER_NOT_ALLOWED = 9
SEPARATOR_NOT_ALLOWED = 10
HEADER_TOO_LONG = 11
UNKNOWN_DP_ERROR = 12
ACCESS_DENIED = 13
DP_OUT_OF_MEMORY = 14
DISK_FULL = 15
DP_TIMEOUT = 16
OTHERS = 17
.
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
loop at itab.
write : / itab-matnr, itab-werks, itab-LGORT.
endloop.
Points if helpfull
2008 Jul 18 4:06 PM
Hello,
IF you have an ALV or a classical report already, then you can directly download the output list to an excel file on the desktop.
If you want to do this programmatically, then use the function module 'GUI_DOWNLOAD' by passing the internal table and you will get the contents of the internal table in the form of a file on yoru desktop.
cheers,
Sushil Joshi
2008 Jul 18 5:13 PM
Hi,
Visit the following link:
http://www.thespot4sap.com/Articles/Download_to_excel.asp
Often we face situations where we need to download internal table contents onto an Excel sheet. We are familiar with the function module WS_DOWNLOAD. Though this function module downloads the contents onto the Excel sheet, there cannot be any column headings or we cannot differentiate the primary keys just by seeing the Excel sheet.
For this purpose, we can use the function module XXL_FULL_API. The Excel sheet which is generated by this function module contains the column headings and the key columns are highlighted with a different color. Other options that are available with this function module are we can swap two columns or supress a field from displaying on the Excel sheet.
Regards,
Srilatha.
2008 Jul 18 5:40 PM
Hi Oscar
There is a Menu bar to be able export the data from the screen(Report) into file type excel sheet and or word.
I forgot the it menu path, I will check and tell you again.
So why that you need the coding at the button to do export?
Cheers.
Wiparat
2008 Jul 18 6:39 PM
HI Oscar,
Check this code:
REPORT zc1download message-id zc1dwnmsg.
&----
*& Declaration Section for the Tables *
&----
TABLES: makt.
&----
*& Declaration Section for the Internal Tables
&----
DATA: intab TYPE TABLE OF makt,
wa_intab LIKE LINE OF intab,
no_of_rec TYPE i,
count TYPE i.
DATA: BEGIN OF f_intab,
str(255) TYPE c,
END OF f_intab.
DATA: t_intab LIKE TABLE OF f_intab,
w_intab LIKE LINE OF t_intab,
temp(255) TYPE c.
FIELD-SYMBOLS: <f> TYPE ANY.
&----
*& Selection ScreenSection for the file download
&----
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
PARAMETERS: file TYPE rlgrap-filename MEMORY ID file,
tab RADIOBUTTON GROUP rad1 DEFAULT 'X',
others RADIOBUTTON GROUP rad1,
delimit TYPE c.
SELECTION-SCREEN END OF BLOCK b1.
START-OF-SELECTION.
IF file IS INITIAL. " check to ensure file.
MESSAGE i001.
EXIT.
ENDIF.
IF others = 'X'. " check to ensure delimiter.
IF delimit = ' '.
MESSAGE i002.
EXIT.
ENDIF.
ENDIF.
SELECT * FROM makt INTO TABLE intab.
IF tab = 'X'. " default delimiter tab is used
CALL FUNCTION 'WS_DOWNLOAD'
EXPORTING
filename = file
filetype = 'DAT'
mode = 'A'
TABLES
data_tab = intab .
ELSE. " If user defind delimiter is to be used
Counts the number of fields *
DO.
ASSIGN COMPONENT sy-index OF STRUCTURE wa_intab TO <f>.
IF sy-subrc 0.
EXIT.
ELSE.
count = count + 1.
ENDIF.
ENDDO.
LOOP AT intab INTO wa_intab.
DO count TIMES. " Adding the delimiter in required places
ASSIGN COMPONENT sy-index OF STRUCTURE wa_intab TO <f>.
CONCATENATE temp delimit <f> INTO temp.
ENDDO.
SHIFT temp.
APPEND temp TO t_intab.
CLEAR temp.
ENDLOOP.
CALL FUNCTION 'WS_DOWNLOAD'
EXPORTING
filename = file
filetype = 'ASC'
mode = 'A'
TABLES
data_tab = t_intab .
ENDIF.
WRITE:/ 'The Data has been tranfered to :', file.
Hope this helps you.
Regards,
Chandra Sekhar
| User | Count |
|---|---|
| 4 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |