Skip to Content
1
Former Member
Jul 19, 2019 at 12:09 PM

Export data from excel sheet to z table.

111 Views

report zalvnew.

parameters: p_ifname type rlgrap-filename.
data : it_data type table of alsmex_tabline initial size 0,
is_data type alsmex_tabline.

types: begin of zstud3,
zstudid1 like zstud3,
zstudname1 like zstud3,
zmaths like zstud3,
zscience like zstud3,
zenglish like zstud3,
end of zstud3.

data : it_tab type table of zstud3 initial size 0,
is_tab type zstud3.
* If Input file name is not initial.
if not p_ifname is initial.
* Upload EXCEL data into internal table
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.
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-zstudid1.
endif.
if is_data-col = '002'.
move is_data-value to is_tab-zstudname1.
endif.
if is_data-col = '003'.
move is_data-value to is_tab-zmaths.
endif.
if is_data-col = '004'.
move is_data-value to is_tab-zscience.
endif.
if is_data-col = '005'.
move is_data-value to is_tab-zenglish.
endif.
at end of row.
append is_tab to it_tab.
clear : is_data.
endat.
endloop.
insert zstud3 from is_tab.


loop at it_tab into is_tab.
write:/ sy-vline,
(10) is_tab-zstudid1, sy-vline,
(10) is_tab-zstudname1, sy-vline,
(10) is_tab-zmaths, sy-vline,
(10) is_tab-zscience, sy-vline,
(10) is_tab-zenglish, sy-vline.


endloop.

I have made a z table 'zstud3' and I'm trying to insert data into this table from excel sheet. But the data is not getting shown in the database. I have never tried fetching entries from excel before.