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

inserting records into database table

Former Member
0 Likes
546

hi experts,

i want to know is there any possibility to insert records into a database table with duplicate primary keys.i.e records having same primary key values.

3 REPLIES 3
Read only

Sm1tje
Active Contributor
0 Likes
520

it can be done from ABAP report with addition 'accepting duplicate keys'.

Inserting Several Lines

To insert several lines into a database table, use the following:

INSERT target FROM TABLE itab [ACCEPTING DUPLICATE KEYS].

This writes all lines of the internal table itabto the database table in one single operation. If one or more lines cannot be inserted because the database already contains a line with the same primary key, a runtime error occurs. You can prevent the runtime error occurring by using the addition ACCEPTING DUPLICATE KEYS.

Whenever you want to insert more than one line into a database table, it is more efficient to work with an internal table than to insert the lines one by one.

Read only

Former Member
0 Likes
520

hi,

U can use accepting duplicate keys with your insert statement.

Thanks

Read only

Former Member
0 Likes
520

please be more precise, It is absolutely impossible to insert duplicate keys into a database table!

But you can insert from an internal table which can have duplicate keys into a database table in an efficient way wuithout getting short-dumps.

This is the method with the 'accepting duplicate keys'. It is o.k., if there are not many or nearly no duplicates. It is not recommended if every second record is in fact a duplicate record.

I guess in most cases it is better, to use either 'DELETE ADJACENT DUPLICATES' or a 'COLLECT' to get rid of the duplicates. You must decide first, how you want to proceed with the duplicates, is it irrelevant which record is inserted, would you like to have a sumed up record, or do you have a condition which should be taken?

Siegfried