‎2010 Oct 05 3:39 PM
Hi ,
I have problem in uploading data into ztable from excel.
I tried to use gui_upload but the data coming is in wrong format.
my code is as follows -
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = p_file
filetype = 'DAT'
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 = t_rec1
* 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.Please use code tagsa to format your code
Edited by: Rob Burbank on Oct 5, 2010 11:07 AM
‎2010 Oct 05 3:58 PM
Dear Deepali,
You mean that you are trying to upload excel sheet file right?? If yes then change the filetype from .dat to .xls.I hope it wil work
‎2010 Oct 05 4:09 PM
Check the documentation for this FM. '#' is not a valid entry for HAS_FIELD_SEPARATOR.
Rob
‎2010 Oct 05 6:42 PM
Hi Rob,
I tried using space as field seperator...but still the problem ecxists....the values are not getting populated in my internal table.
My requirement is that user should be able to load values in ztable usind notepad file or excel file.
Please suggest:)>
Thanks in advance.
‎2010 Oct 05 6:43 PM
‎2010 Oct 05 6:45 PM
‎2010 Oct 05 6:47 PM
Then set has_field_separator to 'X'. (Not space, not '#').
Rob
‎2010 Oct 05 7:10 PM
Hi Rob,
I tried the same but still i am not getting the right data in my internal table.
Below is my changed code -
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = p_file
filetype = 'DAT'
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 = t_rec1
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.
p_file is a string.,
‎2010 Oct 06 11:26 AM
Hi Deepali,
Please change file type to 'ASC'
and check the structure of your table t_rec1 .
It should be ideally same as the file data (text or excel will do but number of columns in file & structure matters).
And seperator 'X' if tab delimited file.
hope this helps
‎2010 Oct 05 6:23 PM
Hi Deepali,
Make Has_field_separator as 'X'. Also try field type 'ASC'.
This should work for you.
Thanks
Edited by: Sumit Naik on Oct 5, 2010 7:26 PM
‎2010 Oct 05 7:15 PM
‎2010 Oct 05 7:17 PM
hi anand,
in my requirement user should able to load data in ztable from text file or excel both.
regardds,
nitin
‎2010 Oct 06 5:49 AM
HI,
what is the field type used in internal table t_rec1 ? use char type .
if the user is going to upload excel or text then u have to i dentify first the file which user is passing is text ot excel. Then according to tat u have to pass the file type .
The FM which anand has suggested the right for excel file upload and for text u can use FM gui_upload.
Regards,
Madhukar Shetty
‎2010 Oct 06 8:00 AM
You should check the file extension if it is txt, use FM GUI_UPLOAD; if it is xls, use FM TEXT_CONVERT_XLS_TO_SAP.
‎2010 Oct 06 5:51 AM
Hi,
Try this code
REPORT ztest.
TYPES : BEGIN OF ty_tab,
entno TYPE zentno,
matnr TYPE matnr,
END OF ty_tab.
DATA: it_upload TYPE STANDARD TABLE OF ty_tab,
wa_upload TYPE ty_tab,
it_final TYPE STANDARD TABLE OF ztafmsdens,
wa_final TYPE ztest.
DATA: v_file TYPE filetable,
v_rc TYPE i,
v_cnt TYPE i VALUE 0,
v_wt TYPE string. " Variable for Window Title
DATA: p_filename TYPE string.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
v_wt = text-007.
CALL METHOD cl_gui_frontend_services=>file_open_dialog
EXPORTING
window_title = v_wt
CHANGING
file_table = v_file
rc = v_rc
EXCEPTIONS
file_open_dialog_failed = 1
cntl_error = 2
error_no_gui = 3
not_supported_by_gui = 4
OTHERS = 5.
IF sy-subrc <> 0.
MESSAGE e398(00) WITH text-005.
ELSE.
READ TABLE v_file INDEX 1 INTO p_file.
ENDIF.
START-OF-SELECTION.
p_filename = p_file.
CALL METHOD cl_gui_frontend_services=>gui_upload
EXPORTING
filename = p_filename
filetype = 'DAT'
dat_mode = space
CHANGING
data_tab = it_upload
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
not_supported_by_gui = 17
error_no_gui = 18
OTHERS = 19.
IF sy-subrc <> 0.
MESSAGE e398(00) WITH text-006.
ENDIF.
END-OF-SELECTION.
LOOP AT it_upload INTO wa_upload.
wa_final-entno = wa_upload-entno.
wa_final-matnr = wa_upload-matnr.
APPEND wa_final TO it_final.
CLEAR wa_final.
v_cnt = v_cnt + 1.
ENDLOOP.
IF it_final[] IS NOT INITIAL.
MODIFY ztest FROM TABLE it_final.
ENDIF.
IF sy-subrc = 0.
WRITE : V_CNT, text-006.
ENDIF.
Regards,
Ragunathan.R
‎2010 Oct 06 7:25 AM
check the data in the file whether it is in correct format and the itab table format there should not be any mismatch.