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: 

Identify Duplicated Records For Primary Key Fields

Former Member
0 Kudos

Does anyone has codes for identifying duplicate records for the primary key in my database table? For an example now i have 2 primary key in my database table.

I need dynamic codes so i can applied it for different tables.

1) How do i check the data in a column if there are duplicate?

( 1 primary key )

<b>Admino</b>

051111

052222

051111

2) How do i check the data of two or more column to see if they are duplicate?

( this means that there are 2 or more primary key )

<b>Admino</b>

<b>Name</b>

051111

John

052222

Mary

051111

John

6 REPLIES 6

Former Member
0 Kudos

Admino | Name |

051111

John

052222

Mary

051111

John

Hi if the first two fileds are key fields the combination is called a primary key. So at any time a table can have only one primary key.

If you insert first record and third record in this sample, system will go for dump.

to avoid that situation u have many options.

1. select the same values (Key fields)from table and insert only if SY-SUBRCis not zero

2. INSERT DBname from itab ACCEPTING DUPLICATE KEYS

Former Member
0 Kudos

For identifying duplicate records the algorithm goes as

Loop at the table

Read the forst and second record

if same move dem in other table

if they r not same read the second and third record and go on

endloop

However an easier way is to use

DELETE ADJACENT DUPLICATES stmt

Reward if helpful

Former Member
0 Kudos

Always use this :

Distrinct keyword is used to remove duplicate entries .

Select <b>Distrinct</b> VBELN POSNR from vbak into corresponding fields of table itab.

reward if useful..

Amit Singla

Message was edited by:

Amit Singla

JozsefSzikszai
Active Contributor
0 Kudos

hi Jocelyn,

this question was raised several times already, but I would be very interesting in seeing any table in SAP with duplicate primary keys...

ec

0 Kudos

primary key must not necessarily be a unique key. It should be, but are you really enforced to do so?

Former Member
0 Kudos

Thanks everyone