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 statement Acepting duplicate Keys ???

NR_Ranasingh
Participant
0 Likes
4,419

Hi ,

i am updating a ztable ZMM_PRIMO_DUPERR from itab I_DPAIR .

in my ztable there is a field PROCESSING_DATE which is the only primary key .

and in my itab i have 2 records on the same processing date . i mean for a particular key, Duplicate record exists in I_DPAIR .

i want to update both records into the ztable.so i write the below code,but its not working, Its only inserting the first record ?

how this below syntax works ??

INSERT ZMM_PRIMO_DUPERR FROM TABLE I_DPAIR ACCEPTING DUPLICATE KEYS

please share your thoughts ..

11 REPLIES 11
Read only

Former Member
0 Likes
2,003

Hi,

As you said its not inserting 2 similar records.

It would never insert 2 records with same primary key.

Otherwise what's the use of primary key.

Read only

0 Likes
2,003

yes you are true ...

But wht is the use of ACCEPTING DUPLIACTE KEYS ??

Read only

Sandeep_Panghal
Product and Topic Expert
Product and Topic Expert
0 Likes
2,003

you have to redesign you DB table.

Read only

Former Member
0 Likes
2,003

Hi Sagar,

Using "Accepting duplicate keys" will only set the sy-subrc = 4 when you try to insert duplicate records into the DB table from an internal table so that we can handle this exception.

Regards,

Read only

0 Likes
2,003

HI Nagraj,

so you mean , the syntax is only to avoid sortdump , but it wont add any dupliacte records .?

Read only

Former Member
0 Likes
2,003

Yes thats correct. In this case all the unique records will be inserted and the duplicates will be rejected.

Read only

Former Member
0 Likes
2,003

Hi,

ACCEPTING DUBLICATE ENTRIES is to avoid the dump.It wont add duplicate entries in the database table.If you don't use the keyword ACCEPTING DUBLICATE ENTRIES, you will get a dump.

Read only

RaymondGiuseppi
Active Contributor
0 Likes
2,003

In case of doubt, read the Abap documentation first [FROM TABLE itab [ACCEPTING DUPLICATE KEYS]|http://help.sap.com/abapdocu_70/en/ABAPINSERT_SOURCE.htm#&ABAP_ALTERNATIVE_2@2@] or via F1, it is cleary written.

(SQL basic : A Primary Key Constraint is an extension of [Unique Key|http://en.wikipedia.org/wiki/Primary_key] Constraint with the addition of a Not Null Constraint)

Regards,

Raymond

Read only

kesavadas_thekkillath
Active Contributor
0 Likes
2,003

Then what is the exact purpose of primary key ?

you have to create one more primary key which together uniquley identifies a record.

Read only

Former Member
0 Likes
2,003

Hi,

Just CHeck this Documentation from SAP :

... ACCEPTING DUPLICATE KEYS

Effect

If a line cannot be inserted, the system does not

terminate with a runtime error but only sets the return value SY-SUBRC to 4. All other lines are inserted after the command is executed

i.e. so as to just avoid the dump we can use this syntax.

But we cannot insert duplicate records in a table.

Any ways if you have to insert duplicate you have to change your primary key's and table design.

Read only

NR_Ranasingh
Participant
0 Likes
2,003

HI ,

Yes now i am clear.. Thanks to all for their valuable tips ..

I have to redesign the DB table.

Thanks to all