2013 Feb 08 4:52 AM
Hi experts,
I want to insert all records from internal table to database table (Dont bother about duplicates as i need all values from internal table) .
i used "insert <dbtable> from <itab> accepting dupplicate keys". Then also it is not allowing to insert duplicates into DB. please advise me.
while defining itab i used "non-unique default keys".
Thanks,
Silviya
2013 Feb 08 6:48 AM
Hi,
This is for sure that its not allowing you to enter duplicate records because of the primary key. If you want to enter all the records in any case, you have to change the primary key. And 1 tip i want to share. I always use update instead of insert. Its always safe.
Regards
Purnand
2013 Feb 08 4:57 AM
Hello Silviya
You cannot enter duplicate records into Data base tables.Here duplicate in the sense you are trying enter one or more records, for which there is a similar record in the database exists with the same primary key.
Only thing you can do is go for UPDATE statement instead of INSERT.
Katrice
2013 Feb 08 5:03 AM
Hi,
U cannot insert duplicate records since u hav a unique key field.
Still you want to insert, well remove the primary key of the DB table created and insert.
Otherwise u can only modify the table entries
Thanks,
Ben
2013 Feb 08 5:05 AM
Hi Silviya,
In your internal table check there is any duplicate records for your database table primery key. If it is you cant to insert else you can..
I hope this will help you.
2013 Feb 08 5:12 AM
hi,
if the keys are specified in the table it won't accept the entry to come in .. So if you can change the db as per your requirement if it is z table it is possible ..
hope it helps,
Vinoth
2013 Feb 08 6:12 AM
Hi Vinoth,
My table is a customizing table only and also i cant get your answer clearly. If you can tell me clearlly please.
Thank YOu.
2013 Feb 08 6:18 AM
Hello John,
Refer following thread
http://scn.sap.com/thread/3224315
See SAP Documentation on INSERT
If, for one or more of the rows to be inserted, a row with the same primary key
or the same unique secondary key already exists and the ACCEPTING DUPLICATE KEYS
addition is specified, the rows are not inserted and sy-subrc is set to 4.
If, in this case, the addition ACCEPTING DUPLICATE KEYS is not specified, no rows are inserted.
Prior to Release 6.10, this raises an exception that cannot be handled; as of Release 6.10,
this raises the exception that can be handled CX_SY_OPEN_SQL_DB.Katrice
2013 Feb 08 7:14 AM
Hi Friend.
You can easily store duplicate entries in table using one column as SERIAL_NUMBER part of primary key as follows
example is
SI.no A B C
1 aaa 111 @@@
2 aaa 111 @@@
3 bbb 222 @@@
using 'INSERT ' keyword u can insert the data from DB table to internal table
Regards
Sujatha Sahu
2013 Feb 08 6:48 AM
Hi,
This is for sure that its not allowing you to enter duplicate records because of the primary key. If you want to enter all the records in any case, you have to change the primary key. And 1 tip i want to share. I always use update instead of insert. Its always safe.
Regards
Purnand
2013 Feb 08 7:14 AM
"Dont bother about duplicates"
The primary key of the table definition are implemented in database via SQL, as a CONSTRAINT of UNIQUE KEY and NOT NULL, and the database must prevent every tricky hint to be able to bypass this, even if you don't bother
So if you want to have multiple "duplicate entries" you MUST add another primary key, like an internal counter managed in your program. or use other type of database table (like INDX where you can EXPORT to database an internal table of data for one set of primary key)
Regards,
Raymond
2013 Feb 08 7:21 AM
Make all the keys in the Table as Primary Keys . Duplicate entries will be allowed
2013 Feb 08 7:37 AM
Hi Thomas,
For eg: Consider a database table ZEMPLOYEE and assume that this table has primary key field Employee_ID.
If you want to insert all the values from you internal table to database table irrespective of duplicate add field counter which will be the part of primary key field and insert.
Now primary key for this ZEMPLOYEE table will be EMP_ID and Counter fields.
Remember to increase the count number to 1 for every new insertion.
loop at itab into wa.
wa_counter = counter + 1.
INSERT ZEMPLOYEE from wa.
endloop.
Emp_ID COUNTER Emp_name Emp_COUNTRY
1000 1 ABC India
1000 2 ABC India