‎2007 Jul 03 7:58 PM
Hello,
I am trying to load data from excel into internal tables.
*********************************************************************************************
REPORT ZdataFromExcel
data: begin of itable occurs 0,
variable1 type char20,
variable2 type char20,
end of itab.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
FILENAME = 'C:/myfile.xls'
FILETYPE = 'ASC'
TABLES
DATA_TAB = itable
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 itable.
write: /10 itable-var1, 30 itable-var2.
endloop.
*********************************************************************************************
I am getting error as <u><b>"File is not availiable"</b></u>.
Is there anything I am missing to put, I have checkted that file is there in the folder mentioned into Filename in the Func module ?
Thanks for your help
Pranav
‎2007 Jul 03 8:09 PM
Hi,
Here your code works ok.
Maybe your file not exist or it is opened.
Regards
‎2007 Jul 03 8:12 PM
Hi.
try using the FM: "ALSM_EXCEL_TO_INTERNAL_TABLE".
Regards.
S
‎2007 Jul 03 8:10 PM
You should try something like this. If the file which are uploading was not downloaded using the GUI_DOWNLOAD funcito module, then the GUI_UPLOAD will most likely give you junk data.
report zrich_0002.
types: begin of ttab ,
fld1(30) type c,
fld2(30) type c,
fld3(30) type c,
fld4(30) type c,
fld5(30) type c,
end of ttab.
data: itab type table of ttab with header line.
selection-screen skip 1.
parameters: p_file type localfile default
'C:test.xls'.
selection-screen skip 1.
at selection-screen on value-request for p_file.
call function 'KD_GET_FILENAME_ON_F4'
exporting
static = 'X'
changing
file_name = p_file.
start-of-selection.
clear itab. refresh itab.
perform upload_data.
loop at itab.
write:/ itab-fld1, itab-fld2, itab-fld3, itab-fld4, itab-fld5.
endloop.
************************************************************************
* Upload_Data
************************************************************************
form upload_data.
data: file type rlgrap-filename.
data: xcel type table of alsmex_tabline with header line.
file = p_file.
call function 'ALSM_EXCEL_TO_INTERNAL_TABLE'
exporting
filename = file
i_begin_col = '1'
i_begin_row = '1'
i_end_col = '200'
i_end_row = '5000'
tables
intern = xcel
exceptions
inconsistent_parameters = 1
upload_ole = 2
others = 3.
loop at xcel.
case xcel-col.
when '0001'.
itab-fld1 = xcel-value.
when '0002'.
itab-fld2 = xcel-value.
when '0003'.
itab-fld3 = xcel-value.
when '0004'.
itab-fld4 = xcel-value.
when '0005'.
itab-fld5 = xcel-value.
endcase.
at end of row.
append itab.
clear itab.
endat.
endloop.
endform.
Regards,
Rich Heilman
‎2007 Jul 03 8:11 PM
The code is ok, just make sure that the file exists and also close the file when you execute the program
‎2007 Jul 03 8:11 PM
Try using a backslash (\) instead of the forward slash (/) in the filename.
Rob
‎2007 Jul 03 8:12 PM
do not use GUI_UPLOAD for XLS File USE FM ALSM_EXCEL_TO_INTERNAL_TABLE
See the below example one :
REPORT ZLWMI151_UPLOAD no standard page heading
line-size 100 line-count 60.
*tables : zbatch_cross_ref.
data : begin of t_text occurs 0,
werks(4) type c,
cmatnr(15) type c,
srlno(12) type n,
matnr(7) type n,
charg(10) type n,
end of t_text.
data: begin of t_zbatch occurs 0,
werks like zbatch_cross_ref-werks,
cmatnr like zbatch_cross_ref-cmatnr,
srlno like zbatch_cross_ref-srlno,
matnr like zbatch_cross_ref-matnr,
charg like zbatch_cross_ref-charg,
end of t_zbatch.
data : g_repid like sy-repid,
g_line like sy-index,
g_line1 like sy-index,
$v_start_col type i value '1',
$v_start_row type i value '2',
$v_end_col type i value '256',
$v_end_row type i value '65536',
gd_currentrow type i.
data: itab like alsmex_tabline occurs 0 with header line.
data : t_final like zbatch_cross_ref occurs 0 with header line.
selection-screen : begin of block blk with frame title text.
parameters : p_file like rlgrap-filename obligatory.
selection-screen : end of block blk.
initialization.
g_repid = sy-repid.
at selection-screen on value-request for p_file.
CALL FUNCTION 'F4_FILENAME'
EXPORTING
PROGRAM_NAME = g_repid
IMPORTING
FILE_NAME = p_file.
start-of-selection.
Uploading the data into Internal Table
perform upload_data.
perform modify_table.
top-of-page.
CALL FUNCTION 'Z_HEADER'
EXPORTING
FLEX_TEXT1 =
FLEX_TEXT2 =
FLEX_TEXT3 =
.
&----
*& Form upload_data
&----
text
----
FORM upload_data.
CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
FILENAME = p_file
I_BEGIN_COL = $v_start_col
I_BEGIN_ROW = $v_start_row
I_END_COL = $v_end_col
I_END_ROW = $v_end_row
TABLES
INTERN = itab
EXCEPTIONS
INCONSISTENT_PARAMETERS = 1
UPLOAD_OLE = 2
OTHERS = 3.
IF SY-SUBRC <> 0.
write:/10 'File '.
ENDIF.
if sy-subrc eq 0.
read table itab index 1.
gd_currentrow = itab-row.
loop at itab.
if itab-row ne gd_currentrow.
append t_text.
clear t_text.
gd_currentrow = itab-row.
endif.
case itab-col.
when '0001'.
t_text-werks = itab-value.
when '0002'.
t_text-cmatnr = itab-value.
when '0003'.
t_text-srlno = itab-value.
when '0004'.
t_text-matnr = itab-value.
when '0005'.
t_text-charg = itab-value.
endcase.
endloop.
endif.
append t_text.
ENDFORM. " upload_data
&----
*& Form modify_table
&----
Modify the table ZBATCH_CROSS_REF
----
FORM modify_table.
loop at t_text.
t_final-werks = t_text-werks.
t_final-cmatnr = t_text-cmatnr.
t_final-srlno = t_text-srlno.
t_final-matnr = t_text-matnr.
t_final-charg = t_text-charg.
t_final-erdat = sy-datum.
t_final-erzet = sy-uzeit.
t_final-ernam = sy-uname.
t_final-rstat = 'U'.
append t_final.
clear t_final.
endloop.
delete t_final where werks = ''.
describe table t_final lines g_line.
sort t_final by werks cmatnr srlno.
Deleting the Duplicate Records
perform select_data.
describe table t_final lines g_line1.
modify zbatch_cross_ref from table t_final.
if sy-subrc ne 0.
write:/ 'Updation failed'.
else.
Skip 1.
Write:/12 'Updation has been Completed Sucessfully'.
skip 1.
Write:/12 'Records in file ',42 g_line .
write:/12 'Updated records in Table',42 g_line1.
endif.
delete from zbatch_cross_ref where werks = ''.
ENDFORM. " modify_table
&----
*& Form select_data
&----
Deleting the duplicate records
----
FORM select_data.
select werks
cmatnr
srlno from zbatch_cross_ref
into table t_zbatch for all entries in t_final
where werks = t_final-werks
and cmatnr = t_final-cmatnr
and srlno = t_final-srlno.
sort t_zbatch by werks cmatnr srlno.
loop at t_zbatch.
read table t_final with key werks = t_zbatch-werks
cmatnr = t_zbatch-cmatnr
srlno = t_zbatch-srlno.
if sy-subrc eq 0.
delete table t_final .
endif.
clear: t_zbatch,
t_final.
endloop.
ENDFORM. " select_data
Thanks
Seshu
‎2007 Jul 03 8:27 PM
Hi,
You can not upload an XLS file using GUI_UPLOAD. Please use following FM to upload XLS files:\
<b>FAA_FILE_UPLOAD_EXCEL
TEXT_CONVERT_XLS_TO_SAP
ALSM_EXCEL_TO_INTERNAL_TABL</b>E
In ALSM_EXCEL_TO_INTERNAL_TABL, you have to format the uploaded date before using it. So, use FAA_FILE_UPLOAD_EXCEL which internally calls ALSM_EXCEL_TO_INTERNAL_TABL, formats data and gives back formatted data in an internal table.
Also, use '\' instead of '/' in C:/myfile.xls'.
You can also call a FM 'F4_FILENAME' to get the file.
Reward points if the answer is helpful.
Regards,
Mukul
Message was edited by:
Mukul R. Kulkarni
‎2007 Jul 03 8:27 PM
HI,
The FILETYPE refer to the type of file format you need: For e.g <b>'WK1' - Excel</b> format , 'ASC' - Text Format etc.
<b>or</b>
Use fm <b>ALSM_EXCEL_TO_INTERNAL_TABLE</b> to upload data frm excel.
<b> follow this link for sample program.</b>
http://www.sapfans.com/forums/viewtopic.php?t=193187&sid=414f896b18c426a3af8c7ef3e9beb6c2
<b>follow these links.</b>
http://www.erpgenie.com/abap/code/abap42.htm
/people/sap.user72/blog/2006/01/19/upload-data-from-multiple-worksheets-within-a-single-excel-file-into-internal-table-from-abap
regards,
Ashok Reddy
‎2007 Jul 03 8:30 PM
Pranav,
I think you are opening the thread not as question. That is why you are not seeing the reward and close buttons.