Application Development 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: 

Insert values into DB Table

Former Member
0 Kudos

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

1 ACCEPTED SOLUTION

former_member188827
Active Contributor
0 Kudos

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.

6 REPLIES 6

Former Member
0 Kudos

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

0 Kudos

>

> 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.

former_member188827
Active Contributor
0 Kudos

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.

sivasatyaprasad_yerra
Active Contributor
0 Kudos

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.

Former Member
0 Kudos

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

Former Member
0 Kudos

Solved