10-12-2007 9:43 AM
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 |
10-12-2007 9:46 AM
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
10-12-2007 9:48 AM
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
10-12-2007 10:00 AM
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
10-12-2007 10:00 AM
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
10-12-2007 10:20 AM
primary key must not necessarily be a unique key. It should be, but are you really enforced to do so?
10-15-2007 9:11 AM