2007 Dec 22 7:58 AM
Hi frnds and gurus. I am new to this SAP and ABAP. Learning right now These technologies. Can any one provide the answer to my doubt. My question is How to upload data from Excel files to SAP. What file type I have to use in GUI_UPLOAD function module. Please help in this issue. Waiting for answer from gurus and frnds.
2007 Dec 22 1:01 PM
Hi,
There is only one FM which uploads native Excel Files into SAP internal tables, search in SE37 for ALSMEXCEL and you'll find it. It uses OLE to work so Excel must be installed on the PC running the program and it must be run in foreground mode.
If you need to upload information from spreadsheets in background mode you need to ask your users to save the files as Tab-Delimited / CSV and use OPEN DATASET to transfer the information into SAP.
Regards,
Satish....
2007 Dec 22 8:02 AM
Hi Sashi,
For exel Sheet Try this function module : ALSM_EXCEL_TO_INTERNAL_TABLE.
Try this example code
REPORT ZCL120_UPLOAD_TIMESHEET.
Parameters:
p_file type RLGRAP-FILENAME
default 'd:\times_internal_20071010', " File Name
p_empid type ZCL_EMPID.
constants:
C_b_c type i value 1, " Begin Col
C_b_r type i value 1, " Begin Row
C_e_c type i value 100, " End Col
C_e_r type i value 500. " End Row
data:
fs_table type ALSMEX_TABLINE, " Work Area for it_table
fs_insert type ZCL_TIME_DATA1. " Work Area for it_insert
data:
Begin of fs_data,
name(30),
Date(40),
Task(15),
Project(15),
Activity(15),
Time(6),
Disc(50),
Status(20),
Bill(5),
end of fs_data.
data:
it_table like table
of fs_table, " Table To Store data Of File
it_data like table
of fs_data, " Store In File Formate.
it_insert like table
of fs_insert. " To Store data like Database Table Formate
Read Exel Sheet
perform read_file Changing it_table.
Convert Data Function Module Structure to file Structure
perform convert using it_table
changing it_data.
Convert Date Formate
perform convert_date changing it_data.
Insert Data for file to Database Table
perform insert using it_data
changing it_insert.
loop at it_data into fs_data.
write / fs_data.
endloop.
&----
*& Form read_file
&----
text
----
<--P_IT_TABLE text
----
FORM read_file CHANGING P_IT_TABLE like it_table[].
CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
FILENAME = p_file
I_BEGIN_COL = c_b_c
I_BEGIN_ROW = c_b_r
I_END_COL = c_e_c
I_END_ROW = c_e_r
TABLES
INTERN = p_it_table
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.
ENDFORM. " read_file
&----
*& Form convert
&----
text
----
-->P_IT_TABLE text
<--P_IT_DATA text
----
FORM convert USING P_IT_TABLE like it_table[]
CHANGING P_IT_DATA like it_data[].
data: w_Temp type i value 1,
w_row type i value 1.
loop at p_it_table into fs_table.
if w_row = fs_table-row.
case w_temp.
when 1.
fs_data-name = fs_Table-value.
when 2.
fs_data-date = fs_table-value.
when 3.
fs_data-task = fs_table-value.
when 4.
fs_data-project = fs_Table-value.
when 5.
fs_data-activity = fs_table-value.
when 6.
fs_data-time = fs_table-value.
when 7.
fs_data-disc = fs_table-value.
when 8.
fs_data-status = fs_table-value.
when 9.
fs_data-disc = fs_table-value.
w_row = w_row + 1.
endcase.
w_temp = w_temp + 1.
if w_temp = 10.
append fs_data to p_it_data.
w_Temp = 1.
clear fs_table.
endif.
*endif.
endloop.
ENDFORM. " convert
&----
*& Form convert_date
&----
text
----
<--P_IT_DATA text
----
FORM convert_date CHANGING P_IT_DATA like it_data[].
data: day(2),
month(2),
year(4),
date(8).
loop at p_it_data into fs_data.
split fs_data-date at '/'
into day month year.
concatenate year month day into date.
fs_data-date = date.
modify p_it_data from fs_data.
endloop.
ENDFORM. " convert_date
&----
*& Form insert
&----
text
----
-->P_IT_DATA text
-->P_IT_INSERT text
----
FORM insert using p_it_data like it_data[]
changing P_IT_INSERT like it_insert[].
data lfs_insert like fs_insert.
loop at p_it_data into fs_data.
Conver Data From File Structure to Table Structure
perform convert_data using fs_data
changing lfs_insert.
insert ZCL_TIME_DATA1 from lfs_insert.
clear lfs_insert.
endloop.
ENDFORM. " insert
&----
*& Form convert_data
&----
text
----
-->P_FS_DATA text
-->P_FS_INSERT text
----
FORM convert_data USING P_fs_DATA like fs_data
CHANGING P_fs_INSERT like fs_insert.
p_fs_insert-mandt = sy-mandt.
p_fs_insert-empid = p_empid.
p_fs_insert-projectid = 'ERP_INT'.
p_fs_insert-WORK_DATE = fs_data-date.
p_fs_insert-objectid = 'SS'.
P_fs_insert-ACTIVITYID = fs_data-activity.
P_fs_insert-ACTIVITYID = 'AC001'.
p_fs_insert-empname = fs_data-name.
p_fs_insert-TIME_WORKED = fs_data-time.
p_fs_insert-DESCRIPTION = fs_data-Disc.
p_fs_insert-status = fs_data-status.
p_fs_insert-BILL_STATUS = fs_data-bill.
ENDFORM. " convert_data
Plz Reward if useful,
*Mahi.
2007 Dec 22 10:41 AM
Hi Sashi,
If you want to upload execl file please check the code below it is very helpful to you.
Data declarations to download data from excel*
data : it_data type standard table of alsmex_tabline initial size 0,
is_data type alsmex_tabline.
Declaration of ty_tab*
types : begin of ty_tab,
bukrs type anla-bukrs,
anln1 type anla-anln1,
anln2 type anla-anln2,
buy_back type anla-buy_back,
end of ty_tab.
Data declarations for ty_tab*
data : it_tab type standard table of ty_tab initial size 0,
is_tab type ty_tab.
start-of-selection.
refresh : it_data, it_tab, it_anla, it_final, it_bdcdata.
Upload data from Excel to internal table format*
call function 'ALSM_EXCEL_TO_INTERNAL_TABLE'
exporting
filename = p_ifname
i_begin_col = 1
i_begin_row = 1
i_end_col = 256
i_end_row = 65356
tables
intern = it_data
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.
Append EXCEL Data into a internal table*
loop at it_data into is_data.
at new row.
clear is_tab.
endat.
if is_data-col = '001'.
move is_data-value to is_tab-bukrs.
endif.
if is_data-col = '002'.
move is_data-value to is_tab-anln1.
call function 'CONVERSION_EXIT_ALPHA_INPUT'
exporting
input = is_tab-anln1
importing
output = is_tab-anln1.
endif.
if is_data-col = '003'.
move is_data-value to is_tab-anln2.
call function 'CONVERSION_EXIT_ALPHA_INPUT'
exporting
input = is_tab-anln2
importing
output = is_tab-anln2.
endif.
if is_data-col = '004'.
move is_data-value to is_tab-buy_back.
endif.
at end of row.
append is_tab to it_tab.
clear is_tab.
endat.
clear : is_data.
endloop.
sort it_tab by bukrs anln1 anln2.
" Now ur data is in internal table.
If you use Text file you can use function module GUI_UPLOAD to upload data to SAP.
<b>Reward if useful</b>
Regards,
sunil kairam.
2007 Dec 22 1:01 PM
Hi,
There is only one FM which uploads native Excel Files into SAP internal tables, search in SE37 for ALSMEXCEL and you'll find it. It uses OLE to work so Excel must be installed on the PC running the program and it must be run in foreground mode.
If you need to upload information from spreadsheets in background mode you need to ask your users to save the files as Tab-Delimited / CSV and use OPEN DATASET to transfer the information into SAP.
Regards,
Satish....
2007 Dec 23 7:18 AM
Use this FM to upload data from Excel file to SAP.
'ALSM_EXCEL_TO_INTERNAL_TABLE'
Check these links for samle coding for excel sheet uploading:
http://www.sap-img.com/abap/upload-direct-excel.htm
http://www.sap-img.com/abap/excel_upload_alternative-kcd-excel-ole-to-int-convert.htm
http://www.sapdevelopment.co.uk/file/file_upexcel.htm
http://www.sapdevelopment.co.uk/ms/mshome.htm
GUI_UPLOAD
GUI_UPLOAD is used to loads a file from the PC to the server. The data can be transferred in binary or text format. Numbers and data fields can be interpreted according to the user settings
For a description of this interface, refer to the documentation for function module, available under SAP Easy Access " Development " Function Builder " Goto " Documentation.
Regards,
Maha
2007 Dec 23 7:30 AM
FORM UPLOAD_FILE .
DATA:IT_EXCEL LIKE ALSMEX_TABLINE OCCURS 0 WITH HEADER LINE.
DATA:BEGIN OF IT_DATA OCCURS 0,
BUKRS LIKE RF02K-BUKRS,
EKORG LIKE RF02K-EKORG,
KTOKK LIKE RF02K-KTOKK,
ANRED LIKE LFA1-ANRED,
NAME1 LIKE LFA1-NAME1,
SORTL LIKE LFA1-SORTL,
LAND1 LIKE LFA1-LAND1,
SPRAS LIKE LFA1-SPRAS,
END OF IT_DATA.
CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
FILENAME = P_FILE
I_BEGIN_COL = '1'
I_BEGIN_ROW = P_BROW
I_END_COL = '50'
I_END_ROW = P_EROW
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.
LOOP AT IT_EXCEL.
CASE IT_EXCEL-COL.
WHEN '001'.
IT_DATA-BUKRS = IT_EXCEL-VALUE.
WHEN '002'.
IT_DATA-EKORG = IT_EXCEL-VALUE.
WHEN '003'.
IT_DATA-KTOKK = IT_EXCEL-VALUE.
WHEN '004'.
IT_DATA-ANRED = IT_EXCEL-VALUE.
WHEN '005'.
IT_DATA-NAME1 = IT_EXCEL-VALUE.
WHEN '006'.
IT_DATA-SORTL = IT_EXCEL-VALUE.
WHEN '007'.
IT_DATA-LAND1 = IT_EXCEL-VALUE.
WHEN '008'.
IT_DATA-SPRAS = IT_EXCEL-VALUE.
ENDCASE.
AT END OF ROW.
APPEND IT_DATA.
CLEAR IT_DATA.
ENDAT.
ENDLOOP.
ENDFORM. " upload_file
Reward if useful
Regards
ANUPAM