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 multiple records from internal table to DB table

Former Member
0 Likes
8,918

Hi Experts,

Can any budy say that How can we insert multiple records from internal table to DB table in a single statment.

Exactly my requirment is I have to insert two DB tables when user push SAVE button, one is header table and second is item table . my problem is in the intrnal table only one record is updating.

Thanks & Regards,

DTK

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
3,951

Hi,

It is all about the primary key fields of the database table.

IE:

You have a db table with following fields

MANDT (primary key field)

BUKRS (primary key field)

BELNR (primary key field)

GJAHR

VBELN

and it with same fields.

MANDT BUKRS BELNR GJAHR VBELN

120 0010 160000 2008 450000

120 0010 160000 2007 450003

120 0020 160000 2008 450000

200 0010 160001 2008 450001

200 0010 160001 2007 450001

If you use INSERT statement, only 3 of these will be inserted into the database table, why?

Because: Each database table must include one or a very small group of key fields that uniquely identify each table line by its value. These fields are known as the primary keys of the table.

And as lines 1 and 2 / 4 and 5 have the same MANDT BUKRS and BELNR only one will be inserted into the table.

If the database table is your own one, you will need to modify it so that it would work.

Good luck!

Hi Experts,

Can any budy say that How can we insert multiple records from internal table to DB table in a single statment.

Exactly my requirment is I have to insert two DB tables when user push SAVE button, one is header table and second is item table . my problem is in the intrnal table only one record is updating.

Thanks & Regards,

DTK

17 REPLIES 17
Read only

Former Member
0 Likes
3,951

INSERT LINES command may help..jus check.

Read only

Former Member
0 Likes
3,951

hi,

use as follows:

modify ztable from internal table.

thanks,

anupama.

Read only

Former Member
0 Likes
3,951

u have to take all the data in internal table which is goig to update in tabel and then use insert statement .

Read only

Former Member
0 Likes
3,951

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

Read only

Former Member
0 Likes
3,951

Hi,

Check out the following link for inserting several lines into database.

http://help.sap.com/saphelp_nw70/helpdata/en/fc/eb3a6d358411d1829f0000e829fbfe/frameset.htm

Regards,

Deepthi

Read only

Former Member
0 Likes
3,951

hi,

u can use "modify dbtab from table itab".

regards,

Sumanjeet.

Read only

Former Member
0 Likes
3,951

hi Devalla,

use MODIFY dbtab from itab

APPEND

for syntax use tcode ABAPDOCU

thanks

Sachin

Read only

Former Member
0 Likes
3,951

Hi,

Besides above, you can also use :

loop at itab into wa.

insert into ztable values wa.

endloop.

attention: the structure of itab should be the same as ztable.

Read only

Former Member
0 Likes
3,951

Hi

You can use the statement

Loop statement

modify ztab from table itab

Append

endloop.

Hope it helps u out

Thanks & Regards

Read only

Former Member
0 Likes
3,951

Hi,

Use

LOOP AT ITAB INTO WA.

modify ztab from table itab

Append

ENDLOOP.

Regards,

Jyothi CH.

Read only

0 Likes
3,951

Hi All,

I CHECK ALL WAYS IT UPDATES ONLY ONE RECORD.

Read only

I355602
Product and Topic Expert
Product and Topic Expert
0 Likes
3,951

Hi Devalla,

Use the statement, to insert records from internal table into ztable in one go:-


MODIFY <ztable_name> FROM <internal_table>.

This statement will INSERT records into the Ztable if no records found corresponding to the key fields.

But if rcords found for key fields, it will work as UPDATE statement into Ztable.

Hope this solves your problem.

Thanks & Regards,

Tarun Gambhir

Read only

0 Likes
3,951

Loop at your internal table and INSERT records one by one..

if it still inserts one record then it means things are wrong with the Key in ur DB or values in internal table..

Check and revert.

Read only

Former Member
0 Likes
3,952

Hi,

It is all about the primary key fields of the database table.

IE:

You have a db table with following fields

MANDT (primary key field)

BUKRS (primary key field)

BELNR (primary key field)

GJAHR

VBELN

and it with same fields.

MANDT BUKRS BELNR GJAHR VBELN

120 0010 160000 2008 450000

120 0010 160000 2007 450003

120 0020 160000 2008 450000

200 0010 160001 2008 450001

200 0010 160001 2007 450001

If you use INSERT statement, only 3 of these will be inserted into the database table, why?

Because: Each database table must include one or a very small group of key fields that uniquely identify each table line by its value. These fields are known as the primary keys of the table.

And as lines 1 and 2 / 4 and 5 have the same MANDT BUKRS and BELNR only one will be inserted into the table.

If the database table is your own one, you will need to modify it so that it would work.

Good luck!

Read only

0 Likes
3,951

Hi Märten Tootmaa,

Thankyou very much.

My problem solved.

Thanks & Regards,

Devalla Tarun Kumar

Read only

Former Member
0 Likes
3,951

Hi Devalla

Could you please tell me how you have solved this problem.

I am also getting same problem.

Regards.

Read only

0 Likes
3,951

Hey, read the post on the first page.