Skip to Content
avatar image
Former Member

removing duplicate entries from database table

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

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

5 Answers

  • avatar image
    Former Member
    Sep 22, 2010 at 09:14 AM

    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

    Add comment
    10|10000 characters needed characters exceeded

  • Sep 22, 2010 at 09:36 AM

    >

    > 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

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Sep 22, 2010 at 09:38 AM

    Hi,

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

    then try to activate using transaction SE14.

    Amitava.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Sep 22, 2010 at 10:06 AM

    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

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Sep 22, 2010 at 09:18 AM
    -1

    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

    Add comment
    10|10000 characters needed characters exceeded