Application Development and Automation 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: 
Read only

Insert data into table

Former Member
0 Likes
1,901

Hi SDN's,

I m new to abap.

could u plz help me.

let us take i m having a table with two fields say eno, ename.

i want to insert da data during runtime,

when i executed, it should display two fields.

i wants to insert data in two fileds, this data sholud save in db table.

how to do that.

plz guide me

thanks in advance

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,766

Hi Renu,

First declare a itab with the fields u want to fill the data base table.

data: begin of itab occurs 0,

eno type string,

ename type tsring,

end of itab.

fill the itab with the data u want to store in database table.

then using insert statement u can insert the data into database table.

insert dbtale from table itab.

<b>u can also insert into database table without using internal table.</b>

tables : databasetable.

databasetable-eno = 'value'.

databasetable-ename = 'value'.

insert databasetable.

here databasetable acts as work area and insert is done into database table from workarea.

16 REPLIES 16
Read only

Former Member
0 Likes
1,766

Hi..

data:

begin of itab occurs 0,

eno , " data types of dbtable

ename, " data types of dbtable

end of itab.

2. Fill the itab with some values.

3. <b>INSERT <dbtab> FROM TABLE <itab> [ACCEPTING DUPLICATE KEYS] .</b>

Read only

Former Member
0 Likes
1,766

Hi Renu,

You can generate Table Maintenance, and then inster the values into DB as shown

1. Go to SE11 and enter the table for which u want to enter values

2. Go to <b>Utilities</b> from menu bar

3. Clk on Table Maintenance Generator

4. Choose Authorization Group and Function Group

5. Clk on Execute.

once u create Table Maintenance, to enter the values go to

1. SM30

2. Enter the Table Maintence name

then it will take you to a screen where you can enter and save the values into DB.

Read only

Former Member
0 Likes
1,767

Hi Renu,

First declare a itab with the fields u want to fill the data base table.

data: begin of itab occurs 0,

eno type string,

ename type tsring,

end of itab.

fill the itab with the data u want to store in database table.

then using insert statement u can insert the data into database table.

insert dbtale from table itab.

<b>u can also insert into database table without using internal table.</b>

tables : databasetable.

databasetable-eno = 'value'.

databasetable-ename = 'value'.

insert databasetable.

here databasetable acts as work area and insert is done into database table from workarea.

Read only

0 Likes
1,766

hi frinds,

i dont want to insert while writing code.

when i executed my program, i screen should hav to input fields,

in those fileds i hav to write the data. when i press save button, these two input field values should save in data base.

plz tell me

Read only

0 Likes
1,766

hi renu ,

for that u have to declare it as parameters soething like this

parameters: databasetable-eno ,

databasetable-ename .

case 'button'.

when 'save' .

insert databasetable.

endcase.

ravi

Read only

0 Likes
1,766

hi ravi,

could u plz provide me sample code.

it wolud be very helpful for me.

thanks in advance

Read only

0 Likes
1,766

hi,

chk this.

REPORT ztestreport .
 
DATA : BEGIN OF int OCCURS 0,
       client LIKE ztable-client,
       emp_name LIKE ztable-emp_name,
       emp_id LIKE ztable-emp_id,
       END OF int.
 
parameters: p_name(35) tyep c ,
                  P_empno(10)n type c.
databasetable-ename .


start-of-selection.

case 'button'.
when 'save' .
int-client = sy-mandt.
int-emp_name = p_name.
int-emp_id = P_empno.
 
APPEND int.
 
INSERT ztable FROM TABLE int.
COMMIT WORK.

endcase.

rgds

Anversha

Read only

0 Likes
1,766

i hav done same thing what u hav done.

but its throughing sme error like

the work are "int" is not long enough

what does it mean

Read only

0 Likes
1,766

hi,

chnage it like this and try.

may be length is an issue.

parameters: p_name like ztable-emp_name,
                  P_empno like ztable-emp_id.

rgds

Anver

Read only

0 Likes
1,766

hi anversha,

i hav done, and its getting executed also.

but its not saving data in database.

y so.

i m giving the code, hav a look n find out whats wrong in this

plzzzz

DATA : BEGIN OF itab OCCURS 3,

empno LIKE zemp-empno,

empname LIKE zemp-ename,

doj like zemp-doj,

END OF itab.

parameters: p_empno like itab-empno,

P_name like itab-empname,

p_doj like itab-doj.

tables zemp.

start-of-selection.

case 'button'.

when 'save' .

itab-empname = p_name.

itab-empno = P_empno.

itab-doj = p_doj.

APPEND itab.

insert zemp into itab.

COMMIT WORK.

endcase.

Read only

0 Likes
1,766

hi renu,

i dont have an sys to check my code just use this logic to develop it it will work

ravi

Read only

0 Likes
1,766

hi,

error is here

<b>insert zemp into itab.</b>

chnage like this.

INSERT zemp FROM TABLE itab.

Rgds

Anver

Read only

0 Likes
1,766

hi

its working now

any wayz thanks sdn's.

Read only

anversha_s
Active Contributor
0 Likes
1,766

hi,

chk this.

REPORT ztestreport .
 
DATA : BEGIN OF int OCCURS 0,
       client LIKE ztable-client,
       emp_name LIKE ztable-emp_name,
       emp_id LIKE ztable-emp_id,
       END OF int.
 
 
int-client = '501'.
int-emp_name = 'Test Data'.
int-emp_id = '0001'.
 
APPEND int.
 
INSERT ztable FROM TABLE int.
COMMIT WORK.

Rgds

Anver

Read only

0 Likes
1,766

hi anversha,

here ur coding for to inseet data like

int-client = '501'.

int-emp_name = 'Test Data'.

int-emp_id = '0001'

but i want to insert this data during runtime when i executed da program.dats wat i m asking

but any ways thanks for ur reply.

do u knw how to do dat method

Read only

Former Member
0 Likes
1,766

Hi Renushree,

Is it possible for you to use select options,one for emp no and other for emp name.

So when you execute it wil insert to the database tables.

No need of internal tables in that case or not much code.

Regards,

Ponraj.s.