‎2009 May 13 9:23 AM
Hi Guys,
I am trying to insert values directly in DB table using Insert statement.
Here is the example code.
INSERT zsd_ord_conf_log FROM TABLE it_log ACCEPTING DUPLICATE KEYS.
LOOP AT it_log INTO wa_log.
INSERT into zsd_ord_conf_log values wa_log. "ACCEPTING DUPLICATE KEYS.
COMMIT WORK.
CLEAR wa_log.
ENDLOOP.
I try both ways above, It insert one only record initially after that, its not allowing any.
MANDT is the only primary key in this table.
Is it anything I need to maintain at the technical settings.
Thanks
‎2009 May 13 9:32 AM
since mandt is only primary key, it wont allow you to enter any values with same mandt.
INSERT target FROM TABLE itab [ACCEPTING DUPLICATE KEYS].
This writes all lines of the internal table to 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.
‎2009 May 13 9:30 AM
Hi sapgeek007,
Updating a DB Table using INSERT Key word is not best practise.
And I could't see any DB table in to code.
Regards,
Suneel G
‎2009 May 13 10:34 AM
>
> Hi sapgeek007,
>
> Updating a DB Table using INSERT Key word is not best practise.
>
> And I could't see any DB table in to code.
>
>
> Regards,
> Suneel G
He's updating a custom Z table so using INSERT is fine. The Z DB table is in the code.....
As mentioned, the problem is that the table doesn't have a proper key - each table record needs to have a unique key to identify it and if the key is MANDT it will only allow a single record to be created in each client. Read the SAP help on creating database tables.
‎2009 May 13 9:32 AM
since mandt is only primary key, it wont allow you to enter any values with same mandt.
INSERT target FROM TABLE itab [ACCEPTING DUPLICATE KEYS].
This writes all lines of the internal table to 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.
‎2009 May 13 9:45 AM
Since MANDT is the only key field, it will insert only one record from the internal table. So, choose appropriate key fields and then try to execute the statement.
Regards,
Siva.
‎2009 May 13 10:56 AM
if MANDT is only primary key then always one record will be inserted in table because in any client all the records have same MANDT value ( Client ).
So solution is use combination of fields with MANDT as primarykey so data will be inserted in table.
Regards,
Chintan
‎2009 Jun 09 3:37 AM