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.

9 REPLIES 9

JozsefSzikszai
Active Contributor
0 Kudos

there cannot be duplicate records for the primary key...

Former Member
0 Kudos

at first there wouldn't be any duplicate records for primary keys ..............

Former Member
0 Kudos

hello friend,

from what u said, i understand that your issue is to find out the combination of fields forming primary key, dynamically in any table that u want. For this u can use DD03L table. write a select query as follows.

ex:

select fieldname

from dd03L

into table t_fields

where tabname = tablename

and fieldname ne 'MANDT'

and keyflag = 'X'.

Former Member
0 Kudos

Because i import a flat file to a database table.

There might have some records added twice during the importing.

So i need to check for data integrity.

Former Member
0 Kudos

hi,

while inserting into DB use like this. it will take care of ur problem.

insert <bd table> from <itab> accepting duplicate keys.

*reward if helpful*

Former Member
0 Kudos

after getting the records to internal table write the statement

delete adjacent duplicate ................... before that write sort stament also......

Deleting Adjacent Duplicate Entries

To delete adjacent duplicate entries use the following statement:

DELETE ADJACENT DUPLICATE ENTRIES FROM <itab>

[COMPARING <f1> <f 2> ...

|ALL FIELDS].

The system deletes all adjacent duplicate entries from the internal table <itab>. Entries are duplicate if they fulfill one of the following compare criteria:

Without the COMPARING addition, the contents of the key fields of the table must be identical in both lines.

If you use the addition COMPARING <f1> <f 2> ... the contents of the specified fields <f 1 > <f 2 > ... must be identical in both lines. You can also specify a field <f i > dynamically as the contents of a field <n i > in the form (<n i >). If <n i > is empty when the statement is executed, it is ignored. You can restrict the search to partial fields by specifying offset and length.

If you use the addition COMPARING ALL FIELDS the contents of all fields of both lines must be identical.

You can use this statement to delete all duplicate entries from an internal table if the table is sorted by the specified compare criterion.

If at least one line is deleted, the system sets SY-SUBRC to 0, otherwise to 4.

Former Member
0 Kudos

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

Message was edited by:

Jocelyn Loo Su Ann

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

thanks everyone.