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: 

removing duplicate entries from database table

Former Member
0 Kudos

Hi All,

Requirement is that we have a database table tab1 like this

id name address

1 AA1 X

1 AA1 X

2 AA2 Y

2 AA2 Y

and we have to insert this data of tab1 into tab2 in this form

id name address

1 AA1 X

AA1 X

2 AA2 Y

AA2 Y

all the duplicate ids are removed .

How an we do this . Please suggest.

thanks

ABAP Developer1

5 REPLIES 5

Former Member
0 Kudos

Hi ,

try this way.

in the Id field remove the Initial check.

and whem u tr to Insert the first value.. do this..


Select Max(Id) from <table> into w_maxid where name = 'XXX".
if sy-subrc eq 0.
    Id = w_maxid + 1.
     name = 'XXX'."dfrom above condition
     Insert above value to table
else.
     Id = 0.
     name = 'XXX'."dfrom above condition
     Insert above value to table
Endif.

Prabhudas

Edited by: Prabhu Das on Sep 22, 2010 2:45 PM

Former Member
0 Kudos

Hi,

Are you using the query "SELECT FOR ALL ENTRIES........."

Then use the statement "SORT <itab> WITH KEY...." And then "DELETE ADJACENT DUPLICATES FROM................"

Hope it will solve your problem.

Thanks&Regards

SuhaSaha
Advisor
Advisor
0 Kudos

>

> Requirement is that we have a database table tab1 like this

> id name address

> 1 AA1 X

> 1 AA1 X

> 2 AA2 Y

> 2 AA2 Y

If your table has these 3 fields only, then i don't think you can have this situation.

DDIC tables can store records with unique keys only. What are the key fields of your DB table ?

BR,

Suhas

Former Member
0 Kudos

Hi,

Change the database table using SE11. put id field as key.

then try to activate using transaction SE14.

Amitava.

Former Member
0 Kudos

If it is database table -

Make the ID as Primary key - It will not allow then duplicate values.

If it is for Internal table calculations in program .

Follow - ITAB[] = ITAB1[]. "Copy the internal tabel values

sort ITAB by key. "Sort by key

Delete adjacent duplicates from ITAB comparing KEY ." Delete the adjacent duplicates using the sorted key