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 values into DB Table

Former Member
0 Likes
1,063

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
Read only

former_member188827
Active Contributor
0 Likes
949

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
Read only

Former Member
0 Likes
949

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

Read only

0 Likes
949

>

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

Read only

former_member188827
Active Contributor
0 Likes
950

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.

Read only

sivasatyaprasad_yerra
Product and Topic Expert
Product and Topic Expert
0 Likes
949

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.

Read only

Former Member
0 Likes
949

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

Read only

Former Member
0 Likes
949

Solved