11-25-2009 9:28 AM
Hello all,
Can anyone tell me how to upload a file which can be either a txt file or an excel file using gui_upload function module .
Currently I am using
CALL METHOD r_obj->gui_upload
EXPORTING
filename = filename
filetype = 'ASC'
has_field_separator = 'X'
IGNORE_CERR = ABAP_TRUE
CHANGING
data_tab = t_filedata
This is working fine for uploading a txt file but not for excel file.
11-25-2009 9:31 AM
Hi,
Search on SCN, you will get many threads.
Refer:- FM ALSM_EXCEL_TO_INTERNAL_TABLE
Regards,
Tarun
11-25-2009 10:26 AM
Hello Guys,
Just a word of caution: ALSM_EXCEL_TO_INTERNAL_TABLE is no longer available in the recent ABAP release.
May be save the excel as CSV or tab-delimited text & proceed with GUI_UPLOAD. You can also refer to this [WIKI |http://wiki.sdn.sap.com/wiki/display/Snippets/Read%20multiple%20sheets%20of%20an%20Excel%20file%20into%20SAP%20through%20ABAP]for details.
Cheers,
Suhas
11-25-2009 10:42 AM
for the Excel you can use this code
DATA : lt_intern TYPE kcde_cells OCCURS 0 WITH HEADER LINE.
DATA : ld_index TYPE i.
FIELD-SYMBOLS: <fs>.
CALL FUNCTION 'KCD_EXCEL_OLE_TO_INT_CONVERT'
EXPORTING
filename = p_file
i_begin_col = 1
i_begin_row = 1
i_end_col = 256
i_end_row = 65000
TABLES
intern = lt_intern
EXCEPTIONS
inconsistent_parameters = 1
upload_ole = 2
OTHERS = 3.
LOOP AT lt_intern.
* P_HEAD is a check box in input that identify if the file has header line.
*So you can skip the first line if is checked.
IF p_head EQ 'X' AND lt_intern-row EQ 1.
CONTINUE.
ENDIF.
MOVE lt_intern-col TO ld_index.
ASSIGN COMPONENT ld_index OF STRUCTURE
tb_file TO <fs>.
MOVE : lt_intern-value TO <fs>.
* TB_FILE is your internal table that stores information from file.
AT END OF row.
APPEND tb_file.
CLEAR tb_file.
ENDAT.
ENDLOOP.
11-25-2009 9:42 AM
Hi Sinthu,
Do as below:-
CALL METHOD cl_gui_frontend_services=>gui_upload
EXPORTING
filename = 'C:\temp\text.xls'
filetype = 'ASC'
has_field_separator = 'X'
CHANGING
data_tab = itab
IF sy-subrc = 0.
WRITE:/ 'success'.
ENDIF.
.
CALL METHOD cl_gui_frontend_services=>gui_upload
EXPORTING
filename = 'C:\temp\text.txt'
filetype = 'ASC'
has_field_separator = 'X'
CHANGING
data_tab = itab
IF sy-subrc = 0.
WRITE:/ 'success'.
ENDIF.
.
Regards
Abhii
11-25-2009 10:18 AM
Hi Dinesh,
You can do it directly by using the Function Module 'GUI_UPLOAD'. It will work both for text and excel.
example:
for Excel file.
DATA: v_file TYPE string VALUE 'C:\Documents and Settings\Desktop\Tps.xls'.
for text file.
DATA: v_file TYPE string VALUE 'C:\Documents and Settings\Desktop\Tps.txt'.
and then the below code.
DATA: BEGIN OF destfile OCCURS 0,
text(250) TYPE c,
END OF destfile.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = v_file
filetype = 'ASC'
* HAS_FIELD_SEPARATOR = ' '
* HEADER_LENGTH = 0
* READ_BY_LINE = 'X'
* DAT_MODE = ' '
* CODEPAGE = ' '
* IGNORE_CERR = ABAP_TRUE
* REPLACEMENT = '#'
* CHECK_BOM = ' '
* VIRUS_SCAN_PROFILE =
* NO_AUTH_CHECK = ' '
* IMPORTING
* FILELENGTH =
* HEADER =
TABLES
data_tab = destfile.
Try using this way. It should work.
Regards,
Bhanu.
11-25-2009 1:03 PM
Hi dinesh,
try this FM CALL FUNCTION 'GUI_FILE_LOAD_DIALOG' & get the path
and thwn use FM CALL FUNCTION 'GUI_UPLOAD'
11-25-2009 1:26 PM
Hi ,
Try the solution given by Abhii but salve the excel file as tab delimited and use that file for upload. It will work.
11-25-2009 2:23 PM