08-01-2008 7:03 AM
Hi gurus,
I am in a need to upload data from an excel file.
I tried using 'GUI_UPLOAD' function , but the file is not being opened.
I am getting an exception message that 'file open error'.
I am giving the file type as 'XLS' , I have tried using file types as 'BIN' and 'DAT' , but still not working.
This is what i am giving,
DATA : it_lum TYPE TABLE OF z0pm_u9_vm_lum,
it_brkt TYPE TABLE OF z0pm_u9_vm_brkt,
file_name TYPE string.
file_name = 'E:\ZQRY_IPOWER_Z0PM_U9_VM_LUM'.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = file_name
filetype = 'XLS'
TABLES
data_tab = it_lum
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 EQ 0.
MODIFY z0pm_u9_vm_lum FROM TABLE it_lum.
WRITE : / ' UPLOAD SUCCESS ' .
ENDIF.
Any pointers on this, will be really appreciated.
Thanks in advance.
Yatin.
08-01-2008 7:12 AM
hiii
for uploading excel file use below code..here gui_upload will not work
*Upload data from Excel sheet to internal table.
CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
filename = p_pfile
i_begin_col = 1
i_begin_row = 2
i_end_col = 13
i_end_row = 8
TABLES
intern = it_excel
EXCEPTIONS
inconsistent_parameters = 1
upload_ole = 2
OTHERS = 3.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
*Populate data to internal tables and structures
SORT it_excel BY row col.
LOOP AT it_excel INTO ls_excel.
CASE ls_excel-col.
WHEN 1.
ls_data-rec_no = ls_excel-value.
IF ls_data-rec_no NE w_docno.
WRITE:
'You Have Entered wrong Document Number'.
ELSE.
WRITE:
'Document Number Same'.
ENDIF. " IF ls_data-rec_no NE w_docno.
WHEN 2.
ls_data-doc_type = ls_excel-value.
WHEN 3.
ls_data-doc_part = ls_excel-value.
WHEN 4.
ls_data-doc_ver = ls_excel-value.
WHEN 5.
ls_data-application = ls_excel-value.
WHEN 6.
ls_data-data_car = ls_excel-value.
WHEN 7.
ls_data-file_path = ls_excel-value.
WHEN 8.
ls_data-matnr = ls_excel-value.
ENDCASE. " CASE ls_excel-col.
regards
twinkal
08-01-2008 7:08 AM
Hi
Use the FM 'alsm_excel_to_internal_table '.This is a better approach becuase you can retrieve the data from the excel sheet row wise and column wise.
Regards
Divya
08-01-2008 7:11 AM
Use trh FM
ALSM_EXCEL_TO_INTERNAL_TABLE for uploading Excel file.
08-01-2008 7:12 AM
hiii
for uploading excel file use below code..here gui_upload will not work
*Upload data from Excel sheet to internal table.
CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
filename = p_pfile
i_begin_col = 1
i_begin_row = 2
i_end_col = 13
i_end_row = 8
TABLES
intern = it_excel
EXCEPTIONS
inconsistent_parameters = 1
upload_ole = 2
OTHERS = 3.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
*Populate data to internal tables and structures
SORT it_excel BY row col.
LOOP AT it_excel INTO ls_excel.
CASE ls_excel-col.
WHEN 1.
ls_data-rec_no = ls_excel-value.
IF ls_data-rec_no NE w_docno.
WRITE:
'You Have Entered wrong Document Number'.
ELSE.
WRITE:
'Document Number Same'.
ENDIF. " IF ls_data-rec_no NE w_docno.
WHEN 2.
ls_data-doc_type = ls_excel-value.
WHEN 3.
ls_data-doc_part = ls_excel-value.
WHEN 4.
ls_data-doc_ver = ls_excel-value.
WHEN 5.
ls_data-application = ls_excel-value.
WHEN 6.
ls_data-data_car = ls_excel-value.
WHEN 7.
ls_data-file_path = ls_excel-value.
WHEN 8.
ls_data-matnr = ls_excel-value.
ENDCASE. " CASE ls_excel-col.
regards
twinkal
08-01-2008 7:24 AM
Hi,
you cannot specify filetype as XLS. It can be either BIN, DAT or ASC.
Try using ASC and set HAS_FIELD_SEPARATOR = 'X'.
Regards,
Mohaiyuddin
Edited by: Mohaiyuddin Soniwala on Aug 1, 2008 11:57 AM
08-01-2008 7:25 AM
Yatin,
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = lcl_filename
filetype = 'ASC'">>>>>>>>>check this
has_field_separator = 'X'">>>>>>>>>also this
TABLES
data_tab = i_input
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.
You can also use this FM TEXT_CONVERT_XLS_TO_SAP
Chk this Link
<a class="jive_macro jive_macro_message" href="" __jive_macro_name="message" modifiedtitle="true" __default_attr="1298016"></a>
<a class="jive_macro jive_macro_thread" href="" __jive_macro_name="thread" modifiedtitle="true" __default_attr="104327"></a>
08-01-2008 7:29 AM
Hi!
As others have told you, use ALSM_EXCEL_TO_INTERNAL_TABLE function module, for reference
Check out this sample code.
REPORT z_file3.
DATA: fname(40),
w_line TYPE i VALUE 1,
w_file TYPE rlgrap-filename.
DATA:
t_tab LIKE
TABLE OF ALSMEX_TABLINE
WITH HEADER LINE.
DATA: fs_tab LIKE LINE OF t_tab.
w_file = 'C:\Documents and Settings\ABC\Desktop\Book1.xls'.
CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
filename = w_file
i_begin_col = 1
i_begin_row = 1
i_end_col = 10
i_end_row = 100
tables
intern = t_tab
EXCEPTIONS
INCONSISTENT_PARAMETERS = 1
UPLOAD_OLE = 2
OTHERS = 3
.
IF sy-subrc NE 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ELSE.
WRITE: 'UPLOAD SUCCESSFUL'.
ENDIF.
fname = '.\z_file.xls'.
OPEN DATASET fname FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
LOOP AT t_tab INTO fs_tab.
TRANSFER fs_tab TO fname.
ENDLOOP.
IF sy-subrc EQ 0.
WRITE: / 'FILE OPENED ON APPS SERVER'.
ELSE.
WRITE: / 'FILE COULD NOT BE OPENED'.
ENDIF.
Regards
Abhijeet
08-01-2008 7:40 AM
Hi ,
At the time of excuting program the file is opened at that time it will gives file_open_error . Pls check that file is closed or not.