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: 

Export data from excel sheet to z table.

Former Member
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.

5 REPLIES 5

Tomas_Buryanek
Active Contributor
0 Kudos

Can you not debug it?
Is there something in it_data after ALSM_EXCEL_TO_INTERNAL_TABLE call?

-- Tomas --

FredericGirod
Active Contributor

Hi

I am surprise the compilator accept that :

types:beginof zstud3,
zstudid1 like zstud3,
zstudname1 like zstud3,
zmaths like zstud3,
zscience like zstud3,
zenglish like zstud3,endof zstud3.

your code is really strange.

You read a file, you put the file in an internal table IT_TAB, you clear the structure IS_TAB and after you try to use this structure to do an insert ... the structure is clear.

Where do you want to put this data ?? in the database ? do you have created the table in the dictionnary?

Fred

0 Kudos

yes I have created the table in the database

FredericGirod
Active Contributor
0 Kudos

So have a look to the help of the INSERT statement from a table

INSERT INTO target FROM TABLE itab [ACCEPTING DUPLICATE KEYS] ...

If you have declared the table in the database, do not declare a type, use the dictionnary

data it_tab type standard table of zmy_dictionnary_table with key ...

ABAP documentation: INSERT