‎2007 Aug 06 12:09 PM
‎2007 Aug 06 12:13 PM
Hi,
Here is the sample code for uploading data through excel.
Just change the fields it will work.
If you still have problem. do get bk.
&----
*& Report UPLOAD_EXCEL *
*& *
&----
*& *
*& Upload and excel file into an internal table using the following *
*& function module: ALSM_EXCEL_TO_INTERNAL_TABLE *
&----
REPORT UPLOAD_EXCEL no standard page heading.
*Data Declaration
*----
data: itab like alsmex_tabline occurs 0 with header line.
Has the following format:
Row number | Colum Number | Value
---------------------------------------
i.e. 1 1 Name1
2 1 Joe
TYPES: Begin of t_record,
name1 like itab-value,
name2 like itab-value,
age like itab-value,
End of t_record.
DATA: it_record type standard table of t_record initial size 0,
wa_record type t_record.
DATA: gd_currentrow type i.
*Selection Screen Declaration
*----
PARAMETER p_infile like rlgrap-filename.
************************************************************************
*START OF SELECTION
call function 'ALSM_EXCEL_TO_INTERNAL_TABLE'
exporting
filename = p_infile
i_begin_col = '1'
i_begin_row = '2' "Do not require headings
i_end_col = '14'
i_end_row = '31'
tables
intern = itab
exceptions
inconsistent_parameters = 1
upload_ole = 2
others = 3.
if sy-subrc <> 0.
message e010(zz) with text-001. "Problem uploading Excel Spreadsheet
endif.
Sort table by rows and colums
sort itab by row col.
Get first row retrieved
read table itab index 1.
Set first row retrieved to current row
gd_currentrow = itab-row.
loop at itab.
Reset values for next row
if itab-row ne gd_currentrow.
append wa_record to it_record.
clear wa_record.
gd_currentrow = itab-row.
endif.
case itab-col.
when '0001'. "First name
wa_record-name1 = itab-value.
when '0002'. "Surname
wa_record-name2 = itab-value.
when '0003'. "Age
wa_record-age = itab-value.
endcase.
endloop.
append wa_record to it_record.
*!! Excel data is now contained within the internal table IT_RECORD
Display report data for illustration purposes
loop at it_record into wa_record.
write:/ sy-vline,
(10) wa_record-name1, sy-vline,
(10) wa_record-name2, sy-vline,
(10) wa_record-age, sy-vline.
endloop.
Regards,
Padmam.
‎2007 Aug 06 12:14 PM
hi,
To transfer an excel file u can use either normal BDC or LSMW.
I am giving one example regarding this,i used recording for this using XK01.
u have to use 'ALSM_EXCEL_TO_INTERNAL_TABLE' fn module.
check below program.
report z_bdcp_xk
no standard page heading line-size 255.
tables : lfa1,rf02k.
data : begin of itab occurs 0,
lifnr like rf02k-lifnr,
ktokk like rf02k-ktokk,
name1 like lfa1-name1,
sortl like lfa1-sortl,
land1 like lfa1-land1,
spras like lfa1-spras,
end of itab.
data : itab1 like alsmex_tabline occurs 0 with header line.
data : b1 type i value 1,
c1 type i value 1,
b2 type i value 10,
c2 type i value 99.
include bdcrecx1.
start-of-selection.
call function 'ALSM_EXCEL_TO_INTERNAL_TABLE'
exporting
filename = 'C:\EXCEL.XLS'
i_begin_col = b1
i_begin_row = c1
i_end_col = b2
i_end_row = c2
tables
intern = itab1
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.
perform organize_uploaded_data.
----
perform open_group.
loop at itab.
perform bdc_dynpro using 'SAPMF02K' '0100'.
perform bdc_field using 'BDC_CURSOR'
'RF02K-KTOKK'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'RF02K-LIFNR'
itab-lifnr.
perform bdc_field using 'RF02K-KTOKK'
itab-ktokk.
perform bdc_dynpro using 'SAPMF02K' '0110'.
perform bdc_field using 'BDC_CURSOR'
'LFA1-SPRAS'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'LFA1-NAME1'
itab-name1.
perform bdc_field using 'LFA1-SORTL'
itab-sortl.
perform bdc_field using 'LFA1-LAND1'
itab-land1.
perform bdc_field using 'LFA1-SPRAS'
itab-spras.
perform bdc_dynpro using 'SAPMF02K' '0120'.
perform bdc_field using 'BDC_CURSOR'
'LFA1-KUNNR'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_dynpro using 'SAPMF02K' '0130'.
perform bdc_field using 'BDC_CURSOR'
'LFBK-BANKS(01)'.
perform bdc_field using 'BDC_OKCODE'
'=ENTR'.
perform bdc_dynpro using 'SAPLSPO1' '0300'.
perform bdc_field using 'BDC_OKCODE'
'=YES'.
perform bdc_transaction using 'XK01'.
perform close_group.
endloop.
form organize_uploaded_data .
sort itab1 by row
col.
loop at itab1.
case itab1-col.
....................................................
when 1.
itab-lifnr = itab1-value.
when 2.
itab-ktokk = itab1-value.
when 3.
itab-name1 = itab1-value.
when 4.
itab-sortl = itab1-value.
when 5.
itab-land1 = itab1-value.
when 6.
itab-spras = itab1-value.
....................................................
endcase.
at end of row.
wa_tabdata-mandt = sy-mandt.
APPEND wa_tabdata TO it_tabdata.
CLEAR: wa_tabdata.
append itab.
clear itab.
endat.
endloop.
IF U WANT TO UPLOAD DATA USING LSMW,then u have to save excel file as .CSV FORMAT AND REMAINING STEPS ARE SAME.
Regards
‎2007 Aug 06 12:16 PM
Hi,
do like this
data:s_file type string value 'c:\vendor.xls'.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
FILENAME = S_FILE
FILETYPE = 'ASC'
HAS_FIELD_SEPARATOR = 'X'
TABLES
DATA_TAB = i_lifnr.
rgds,
bharat.
‎2007 Aug 06 12:17 PM
Hi,
U can use FM 'ALSM_EXCEL_TO_INTERNAL_TABLE' to upload excel file into internal table.
CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
filename = p_file
i_begin_col = '1'
i_begin_row = '1' "Do not require headings
i_end_col = '10'
i_end_row = '10000'
TABLES
intern = itab
EXCEPTIONS
inconsistent_parameters = 1
upload_ole = 2
OTHERS = 3.
IF sy-subrc <> 0.
MESSAGE e001(zz) WITH text-005.
"Problem uploading Excel Spreadsheet
ENDIF.
after successful uploading of excel file to internal table u can bdc recording to upload it into sap tables using BDC.
Regards,
Sankar