07-20-2011 3:59 PM
Hi,
I have made a program using FM GUI_UPLOAD to upload an .xls file to an internal table. But upon executing ,it gives error "Cannot Interpret data in file". I have seen in other posts people talking about GUI_UPLOAD FM to upload data from excel directly into internal table. Kindly help.
Here is my code. I had tried using different combination for HAS_FIELD_SEPARATOR but still its not working.
In my emp1.xls file , the data in each column is present in the same order as in the internal table. Although the first column in my internal table is NUMC. I dont know if that is causing the problem.
REPORT ZUPLOAD_1.
data: itab TYPE TABLE OF zempl_master WITH HEADER LINE.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
FILENAME = 'C:\empl1.xls'
FILETYPE = 'ASC'
HAS_FIELD_SEPARATOR = 'X'
* 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 = 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-emp_no,itab-name.
endloop.
07-20-2011 5:25 PM
Hi,
FM GUI_UPLOAD only suitable for text file, not an excel file.
Try to use FM TEXT_CONVERT_XLS_TO_SAP, this function is very simple, even we don't need to define starting row/column and ending row/column, all rows containing data will be transferred to internal table.
Hope this can help you.
Regards,
Ramses Hutahaean
07-20-2011 4:40 PM
Use FM ALSM_EXCEL_TO_INTERNAL_TABLE instead. There are plenty of threads on the forum describing how to use it.
Rob
07-20-2011 5:25 PM
Hi,
FM GUI_UPLOAD only suitable for text file, not an excel file.
Try to use FM TEXT_CONVERT_XLS_TO_SAP, this function is very simple, even we don't need to define starting row/column and ending row/column, all rows containing data will be transferred to internal table.
Hope this can help you.
Regards,
Ramses Hutahaean
07-21-2011 8:29 AM
hi amber22 you need to use the below fm to upload an xls file
FORM EXCEL_UPLOAD .
CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
FILENAME = FILENAM
I_BEGIN_COL = 1
I_BEGIN_ROW = 1
I_END_COL = 6
I_END_ROW = 100
TABLES
INTERN = xl_itab.
* EXCEPTIONS
* INCONSISTENT_PARAMETERS = 1
* UPLOAD_OLE = 2
* OTHERS = 3 .
IF SY-SUBRC = 0.
MESSAGE 'DATA UPLOADED SUCCESSFULLY' TYPE 'I'.
ENDIF.
ENDFORM. " EXCEL_UPLOAD
07-21-2011 8:44 AM
HI Amber,
+ Although the first column in my internal table is NUMC.+ .This is not an issue.
use f4_filename and then use ALSM_EXCEL_TO_INTERNAL_TABLE.
Regards,
Madhu.