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

inserting duplicate value into custom table

Former Member
0 Likes
3,273

HI

I have created a custom table containing 5 fields .there are two primary key fields MANDT,MIRN(custom field).

When I am trying to insert duplicate value into custom table using " INSERT YMCR296 from TABLE git_table ACCEPTING DUPLICATE KEYS." It is not updating the cuplicate values.Please Help

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,794

Hi,

Accepting duplicate keys is not to update the table with the duplicate entries. It simply avoids the dump for DUPREC.

If you want to add a record with the same mandt and MIRN fields, Add another field also as a primary key.

Hope it helps.

Sujay

6 REPLIES 6
Read only

Former Member
0 Likes
1,795

Hi,

Accepting duplicate keys is not to update the table with the duplicate entries. It simply avoids the dump for DUPREC.

If you want to add a record with the same mandt and MIRN fields, Add another field also as a primary key.

Hope it helps.

Sujay

Read only

Former Member
0 Likes
1,794

Hi,

See SAP Documentation on INSERT

If, for one or more of the rows to be inserted, a row with the same primary key 
or the same unique secondary key already exists and the ACCEPTING DUPLICATE KEYS 
addition is specified, the rows are not inserted and sy-subrc is set to 4. If, in this case, 
the addition ACCEPTING DUPLICATE KEYS is not specified, no rows are inserted. 
Prior to Release 6.10, this raises an exception that cannot be handled; as of Release 6.10, 
this raises the exception that can be handled CX_SY_OPEN_SQL_DB.

Regards

Vinod

Read only

Former Member
0 Likes
1,794

Hi,

Instead of insert use modify statement to update the database records.

Whenever you update any custom table always use modify statement instead of insert to update duplicate values.

Hope it hepls.

Karishma.

Edited by: Karishma Kadivar on Sep 3, 2010 1:05 PM

Edited by: Karishma Kadivar on Sep 3, 2010 1:14 PM

Read only

kesavadas_thekkillath
Active Contributor
0 Likes
1,794

If you are inserting duplicate values then what is the need of primary key in your table?

Read only

syed_ibrahim5
Active Participant
0 Likes
1,794

hi,

try to use some sort of an dummy deletion indicator as the primary key by concatenating date and time which would be unique always and that would enable the insertion of duplicate entries...

with regards,

syed

Read only

Former Member
0 Likes
1,794

Hi,

Add 1 more column as key say CNTR type NUMC. Increment this whenevr you add any duplicate entry. You can check duplicate entry by checking Sy-SUBRC = 4 when you use INSERT statement. For example :


INSERT ZTABLE FROM WA_ZTABLE.

IF SY-SUBRC <> 0.

SELECT MAX( CNTR ) FROM ZTABLE INTO WA_ZTABLE-CNTR
              WHERE MIRN = WA_ZTABLE-MIRN.

WA_ZTABLE-CNTR = WA_ZTABLE-CNTR + 1.

INSERT ZTABLE FROM WA_ZTABLE.

ENDIF.

Thanks & Regards,

Rock.