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

Problem in Insert Statement

Former Member
0 Likes
3,421

Dear All,

I had Create one MOdule- Pool Programme. when i insert data in Z DB table only update first line. multiple line item are not inserted in DB table.

Code is Below.

INSERT zgateentry
            FROM TABLE IT_INSERT
            ACCEPTING DUPLICATE KEYS.

Regards,

Rakesh,

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
2,191

Dear Vignesh,

  pl give me syntax.

regards,

Rakesh

11 REPLIES 11
Read only

vinoth_aruldass
Contributor
0 Likes
2,191

hi,

loop it_insert into wa_insert.

insert zgateentry from wa_insert.

endloop.

try this ....

hope it helps,

Vinoth

Read only

0 Likes
2,191

Hi Rakesh,

If a row with the same primary key or the same unique secondary index exists in

the database table for one or more of the rows to be inserted, these rows cannot

be inserted.

If addition ACCEPTING DUPLICATE KEYS is specified, all rows will be inserted which satisfies the condition duplicate keys and the remaining rows are rejected and sy-subrc equal to 4.u can check sy-dbcnt will shown the number of rows inserted.

Regards,

Vignesh Yeram

Read only

vigneshyeram
Active Participant
0 Likes
2,191

Hi Rakesh,

If a row with the same primary key or the same unique secondary index exists in

the database table for one or more of the rows to be inserted, these rows cannot

be inserted.

If addition ACCEPTING DUPLICATE KEYS is specified, all rows will be inserted which satisfies the condition duplicate keys and the remaining rows are rejected and sy-subrc equal to 4.u can check sy-dbcnt will shown the number of rows inserted.

Regards,

Vignesh Yeram

Read only

kakshat
Product and Topic Expert
Product and Topic Expert
0 Likes
2,191

Hi,

It should work. Can you post the contents of your internal table? I hope you are not expecting duplicate records to be inserted in the database table. That won't happen even if you use ACCEPTING DUPLICATE KEYS. This addition does not allow you to add duplicate records in a database table. Just that if your internal table has duplicate records, it prevents a runtime error if you try to insert those records in the database. If your internal table has duplicate records and you don't use the addition ACCEPTING DUPLICATE KEYS, then you would get a runtime error.

Read only

0 Likes
2,191

Hi Akshat,

I meant the same, may be where Rakesh is trying, internal table might contain duplicate records.it's better if he post the contents of the internal table.

If a row with the same primary key or the same unique secondary index exists in

the database table for one or more of the rows to be inserted, these rows cannot

be inserted it will give dump

If addition ACCEPTING DUPLICATE KEYS is specified, all rows will be inserted which is unique and the remaining rows are rejected and sy-subrc equal to 4.you can check sy-dbcnt will shown the number of rows inserted.

Regards,

Vignesh Yeram

Read only

Former Member
0 Likes
2,192

Dear Vignesh,

  pl give me syntax.

regards,

Rakesh

Read only

0 Likes
2,191

Hi Rakesh,

Syntax is :-

1) INSERT dbtab FROM  table itab ACCEPTING DUPLICATE KEYS.

Could you please paste the entries present in internal table and database table so that it will be better to understand the expected output from you and the problem.

2) if this does not work please use:-

    MODIFY dbtab FROM itab.

    COMMIT WORK.

It is better to update database table once instead of hitting the database again n again inside the loop.

Regards,

Vignesh Yeram

Read only

0 Likes
2,191

Dear vignesh,

i had already use both syntax but not working.

my internal table data are below,


2    1    000000000130    20130222    RAKES    RAKESH    AADDINATH CORPORATION    FDAS    SPLENDER    231321    090243    000000

2     2    000000000130    20130222    RAKES    RAKESH    AADDINATH CORPORATION    FDAS    SPLENDER    HULB    090243    000000

in iternal table there is 2 line item but, in DB table store only one line Item.in DB Table one Primary key. first row (2) is Primarty key.

In DB Table :

2100000000013020130222RAKESRAKESHAADDINATH CORPORATIONFDASSPLENDER231321090243000000

store only first Entry...

Regards,

Rakesh

Read only

0 Likes
2,191

Dear Rakesh,

If a row with the same primary key or the same unique secondary index exists in

the database table for one or more of the rows to be inserted, these rows cannot

be inserted, it means in ur case primary key is the first only field 000000000130 in it is already present in DB table, so you try to insert same value 000000000130 again it will not be inserted it will give dump. if dump is to be avoided then u can also use

INSERT dbtab FROM  table itab ACCEPTING DUPLICATE KEYS
But in this case also same primary key will not be inserted it should be unique always.if the internal table contains two entries with same primary key only first entry will be inserted with above syntax if database table does not have the same primary key.

if you want to insert all the records you have to increase the primary key fields.

the concept is you cannot insert the same primary key again.
Hope above explanation helps you.

Regards,

Vignesh Yeram

Read only

Former Member
0 Likes
2,191

dear vinoth,

i had already use that but not working.

regards,

Rakesh

Read only

0 Likes
2,191

hi,

if you need all the entries don assign the key figure in the table ..

hope it helps,

Vinoth