2005 Jun 27 11:01 PM
hi I have an internal table with data in it,
I want to transfer the data to an excel file to be transfered to our unix drive.
I have searched the FM's and the forum but never found a resolved thread for this.
anybody have any ideas.
thanks
2005 Jun 28 4:46 AM
Hi Jamie,
Download internal table to Application server file(Unix)
DATA: e_file like rlgrap-filename value '/usr/sap/tmp/file.txt'.
open dataset e_file for output in text mode.
lOOP AT it_datatab......
transfer it_datatab to e_file.
ENDLOOP.
close dataset e_file.
***
Also, Check this code sample:
&----
*& Form f1104_download_to_lofile
&----
Download to data from internal table to Logical File
----
FORM f100_download_to_lofile.
Data: v_filepht LIKE FILENAME-FILEINTERN, "Physical file for p_fnam2.
Open the file in application server
OPEN DATASET v_filepht FOR OUTPUT IN TEXT MODE.
IF sy-subrc <> 0.
MESSAGE s010 WITH v_filepht. " File opening error
LEAVE LIST-PROCESSING.
ENDIF.
LOOP AT i_logfile INTO w_logfile.
TRANSFER w_logfile TO v_filepht.
CLEAR w_logfile.
ENDLOOP.
IF sy-subrc = 0.
WRITE:/ text-022, v_filepht, text-023. " File successfully created
ELSE.
WRITE:/ text-033, v_filepht. " Error creating file
ENDIF.
Closing the file
CLOSE DATASET v_filepht.
ENDFORM. " f1100_download_to_lofile
Also check this link for Excel download in Application Server:
Regards,
Anjali
Message was edited by: Anjali Devi
2005 Jun 28 1:48 AM
Hi Bullen
you can try fm 'GET_FIELDTAB' and 'EXCEL_OLE_STANDARD_DAT'
Here is an example
-
TABLES: USR03, DD02L.
DATA: ZX030L LIKE X030L.
DATA:BEGIN OF ZDFIES OCCURS 0,
INCLUDE STRUCTURE DFIES,
END OF ZDFIES.
DATA:BEGIN OF FLDITAB OCCURS 0,
FLDNAME(11) TYPE C,
END OF FLDITAB.
DATA ITABUSR03 LIKE USR03 OCCURS 0 WITH HEADER LINE.
DATA TNAME LIKE DD02L-TABNAME.
SELECT * FROM USR03 INTO TABLE ITABUSR03.
TNAME = 'USR03'.
CALL FUNCTION 'GET_FIELDTAB'
EXPORTING
LANGU = SY-LANGU
ONLY = SPACE
TABNAME = TNAME
WITHTEXT = 'X'
IMPORTING
HEADER = ZX030L
TABLES
FIELDTAB = ZDFIES
EXCEPTIONS
INTERNAL_ERROR = 01
NO_TEXTS_FOUND = 02
TABLE_HAS_NO_FIELDS = 03
TABLE_NOT_ACTIV = 04.
IF SY-SUBRC = 0.
LOOP AT ZDFIES.
FLDITAB-FLDNAME = ZDFIES-FIELDNAME.
APPEND FLDITAB.
ENDLOOP.
ELSE.
EXIT.
ENDIF.
CALL FUNCTION 'EXCEL_OLE_STANDARD_DAT'
EXPORTING
FILE_NAME = 'C:\TEST.XLS'
DATA_SHEET_NAME = 'SHEET ONE'
TABLES
DATA_TAB = ITABUSR03
FIELDNAMES = FLDITAB
EXCEPTIONS
FILE_NOT_EXIST = 1
FILENAME_EXPECTED = 2
COMMUNICATION_ERROR = 3
OLE_OBJECT_METHOD_ERROR = 4
OLE_OBJECT_PROPERTY_ERROR = 5
INVALID_PIVOT_FIELDS = 6
DOWNLOAD_PROBLEM = 7
OTHERS = 8.
or, you can also use fm 'ws_download' to download data as xls file.
Message was edited by: Slam Yang
2005 Jun 28 4:46 AM
Hi Jamie,
Download internal table to Application server file(Unix)
DATA: e_file like rlgrap-filename value '/usr/sap/tmp/file.txt'.
open dataset e_file for output in text mode.
lOOP AT it_datatab......
transfer it_datatab to e_file.
ENDLOOP.
close dataset e_file.
***
Also, Check this code sample:
&----
*& Form f1104_download_to_lofile
&----
Download to data from internal table to Logical File
----
FORM f100_download_to_lofile.
Data: v_filepht LIKE FILENAME-FILEINTERN, "Physical file for p_fnam2.
Open the file in application server
OPEN DATASET v_filepht FOR OUTPUT IN TEXT MODE.
IF sy-subrc <> 0.
MESSAGE s010 WITH v_filepht. " File opening error
LEAVE LIST-PROCESSING.
ENDIF.
LOOP AT i_logfile INTO w_logfile.
TRANSFER w_logfile TO v_filepht.
CLEAR w_logfile.
ENDLOOP.
IF sy-subrc = 0.
WRITE:/ text-022, v_filepht, text-023. " File successfully created
ELSE.
WRITE:/ text-033, v_filepht. " Error creating file
ENDIF.
Closing the file
CLOSE DATASET v_filepht.
ENDFORM. " f1100_download_to_lofile
Also check this link for Excel download in Application Server:
Regards,
Anjali
Message was edited by: Anjali Devi
2005 Jun 28 12:31 PM
hi,
I see that fm SAP_CONVERT_TO_XLS_FORMAT is the one I want to use, what do you know what type table of the excel internal table will be?
thanks.
2005 Jun 28 1:26 PM
Hi,
Check this sample code.
It can be any table.
report y_xls .
data: begin of i_datos occurs 100,
a1(10),
a2(20),
a3 type lips-lfimg,
end of i_datos.
start-of-selection.
i_datos-a1 = 'Celda1'.
i_datos-a2 = 'Descripción 1'.
i_datos-a3 = 5.
append i_datos.
i_datos-a1 = 'Celda2'.
i_datos-a2 = 'Descripción 2'.
i_datos-a3 = 6.
append i_datos.
call function 'SAP_CONVERT_TO_XLS_FORMAT'
exporting
I_FIELD_SEPERATOR =
I_LINE_HEADER =
i_filename = 'c:xls.xls'
I_APPL_KEEP =
tables
i_tab_sap_data = i_datos
CHANGING
I_TAB_CONVERTED_DATA =
exceptions
conversion_failed = 1
others = 2
.
if sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
endif.
2005 Jun 28 1:52 PM
Hi Jamie ,
here's another sample:
REPORT ZCONVERTTOXLS .
parameters: p_file like rlgrap-filename default 'c:tmptest.xls'.
data: itab like t001 occurs 0 with header line.
select * from t001 into table itab.
CALL FUNCTION 'SAP_CONVERT_TO_XLS_FORMAT'
EXPORTING
I_FILENAME = p_file
TABLES
I_TAB_SAP_DATA = itab.
regards Andreas
| User | Count |
|---|---|
| 4 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |