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: 

How to send data from excel file in al11 to my custom table(ztable) using read dataset.

former_member828672
Discoverer
0 Kudos
833

Hello Experts,

I Have created a program to get the data from application server using open, read & close dataset into internal tables but im not able to update my custom table with those records taken from excel file in application server.

TABLES : zts_len_data.

DATA : p_file_n TYPE localfile.

TYPES : BEGIN OF zts_len_data,
emp_id TYPE zts_len_data-empl_id,
name TYPE zts_len_data-name,
short_id TYPE zts_len_data-usr_id,
Date_of_Swipe TYPE zts_len_data-date_of_swipe,
First_in_time type zts_len_data-first_in_time,
last_out_time TYPE zts_len_data-last_out_time,
END OF zts_len_data.

DATA: it_tab TYPE TABLE OF zts_len_data,
wa_tab TYPE zts_len_data.

p_file_n = '/tmp/sk.csv'.

OPEN DATASET p_file_n FOR INPUT IN TEXT MODE ENCODING DEFAULT.
IF sy-subrc = 0.
DO.
READ DATASET p_file_n INTO wa_tab.
IF sy-subrc EQ 0.
APPEND wa_tab TO it_tab.
ELSE.
EXIT.
ENDIF.
ENDDO.
ENDIF.
CLOSE DATASET p_file_n.

insert zts_len_data FROM wa_tab.


IF it_tab IS NOT INITIAL.
LOOP AT it_tab INTO wa_tab.
WRITE: / wa_tab-empl_id, wa_tab-name, wa_tab-usr_id, wa_tab-date_of_swipe, wa_tab-first_in_time, wa_tab-last_out_time.
ENDLOOP.
ENDIF.

File records are coming in output but not able to insert in ztable. please help any one.

6 REPLIES 6

higorgranero1
Explorer
625

Hello Siva, how are you ?

You are changing workareas instead internal table to insert into your Z Table.

To resolve your problem, change the sentense:

insert zts_len_data FROM wa_tab.

To the sentense:

MODIFY  zts_len_data FROM TABLE it_tab

I think, it gonna help you.

Thanks,
Higor Granero

0 Kudos
625

Hi Lopes,

Good, how about yourself?

Thanks for the solution. It is working😊. But i need to split the records otherwise data is going incorrectly like in one filed, 2 or 3 details are storing.

Jeansy
Active Contributor
0 Kudos
625

Hi,

the problem is that your statement

insert zts_len_data FROM wa_tab.

just inserts the single entry which is stored in the mentioned work area. But as you are working with several entries to be inserted, you could replace it with

INSERT zts_len_data FROM TABLE it_tab.

Here you can get more information:

Documentation INSERT

Furthermore, do not forget to commit your changes using COMMIT WORK.

I hope this helps you.

Kind regard
Jens

625

Hi Zahringer,

How are you?

Thanks for the solution. It is working.

Jeansy
Active Contributor
0 Kudos
625

Hi Siva,

perfect 🙂 Could you please mark this question as answered?

Kind regards
Jens

Sandra_Rossi
Active Contributor
625

Please edit your question, select your code and press the button [CODE], which makes the code appear colored/indented, it will be easier for people to look at it. Thank you!