Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

lsmw doubt.

Former Member
0 Kudos

hi all ,

i have one excel file (.csv).

and in that i have three worksheet.

i can read the data from first worksheet using function module(alsm_excel_to_internal_table).

<b>how i read data from second worksheet into internal table.

how to fetch data from second worksheet from same excel file.</b>

help me.

thank you.

1 REPLY 1

Former Member
0 Kudos

Hi,

this might be helpful

eport zrich_0001.

include ole2incl.

data: e_sheet type ole2_object.

data: e_appl type ole2_object.

data: e_work type ole2_object.

data: e_col1 type ole2_object.

data: e_col2 type ole2_object.

data: e_cols type ole2_object.

data: e_cell type ole2_object.

data: e_wind type ole2_object.

data: field_value(30) type c.

parameters: p_file type localfile default 'C:\RichTest.xls'.

start-of-selection.

  • Start the application

create object e_appl 'EXCEL.APPLICATION'.

set property of e_appl 'VISIBLE' = 1.

  • Open the file

call method of e_appl 'WORKBOOKS' = e_work.

call method of e_work 'OPEN'

exporting

#1 = p_file.

  • Write data to the excel file

do 20 times.

  • Create the value

field_value = sy-index.

shift field_value left deleting leading space.

concatenate 'Cell' field_value into field_value separated by space.

  • Position to specific cell in Column 1

call method of e_appl 'Cells' = e_cell

exporting

#1 = sy-index

#2 = 1.

  • Set the value

set property of e_cell 'Value' = field_value .

  • Position to specific cell in Column 2

call method of e_appl 'Cells' = e_cell

exporting

#1 = sy-index

#2 = 2.

  • Set the value

set property of e_cell 'Value' = field_value .

  • Position to specific cell in Column 3

call method of e_appl 'Cells' = e_cell

exporting

#1 = sy-index

#2 = 3.

  • Set the value

set property of e_cell 'Value' = field_value .

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.