10-08-2007 10:21 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.
10-08-2007 10:28 AM
10-08-2007 10:38 AM
at first there wouldn't be any duplicate records for primary keys ..............
10-08-2007 10:38 AM
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'.
10-08-2007 10:41 AM
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.
10-08-2007 10:44 AM
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*
10-08-2007 10:48 AM
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.
10-12-2007 9:36 AM
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
10-12-2007 9:42 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-15-2007 9:14 AM