Skip to Content
author's profile photo Former Member
Former Member

Find duplicated records in sorted internal table

hi,

Currently i have an internal table containing more than 100K records and this table has only 1 field.

All records are sorted in ascending order.

Is there any commands or coding i can reference to identify duplicated records, and saved these duplicates into another internal table?

Appreciate if any guru can advise, thanks.

Regards,

JL

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

10 Answers

  • Best Answer
    Posted on Jun 18, 2008 at 09:25 AM

    let us suppose your internal table is itab and two have two workareas itab_wa and itab_oldwa

    loop at itab into itab_wa.
     if itab_wa = itab_oldwa.
     append itab_wa to itab2.
     endif.
     itab_oldwa = itab_wa.
    endloop.
    
    

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jun 18, 2008 at 09:32 AM

    Hi ,

    If your objective is to have only unique record then write this statement and your objective will be full filled.

    DELETE ADJACENT DUPLICATES FROM TABLE itab COMPARING ALL FIELD.

    IF YOU HAVE TO FIND REPEATATIVE RECORDS THEN see the below code.

    LOOP AT itab into wa1.
       n = sy-tabix + 1.
       read table itab into wa2 index n.
         if sy-subrc = 0 .
          wa1 = wa2.
          append wa2 to itab2.
        endif.
    endloop.

    change the name accordingly.

    Reward some points.

    Regards,

    Anomitro Guha

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Jun 18, 2008 at 09:23 AM

    hi,

    if u want to remove that particular duplicate records u can do it.

    check this sample code.

    FORM join_details .

    IF NOT it_pa0000[] IS INITIAL.

    SELECT pernr begda werks btrtl orgeh persk plans kostl aedtm

    FROM pa0001 INTO CORRESPONDING FIELDS OF

    TABLE it_pa0001 FOR ALL ENTRIES IN it_pa0000

    WHERE pernr = it_pa0000-pernr AND

    aedtm > date1.

    SORT it_pa0001 BY pernr aedtm.

    DELETE ADJACENT DUPLICATES FROM it_pa0001 COMPARING pernr.

    endif.

    endform.

    reward points if hlpful.

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Jun 18, 2008 at 09:23 AM

    suppose ur table is itab.

    declare another table of same type itab2

    declare 2 workareas of type itab...say wa_itab1, wa_itab2

    then

    loop at itab into wa_itab1.

    if wa_itab1 = wa_itab2.

    append wa_itab1 to itab2.

    wa_itab2 = wa_itab1.

    endloop.

    itab2 ll contain the duplicate entires

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jun 18, 2008 at 09:23 AM

    Hi!

    SORT itab1 BY key.   "key is the first column
    CLEAR lv_key.
    LOOP AT itab1.
    IF lv_key = itab1-key.   "duplicated entry
    MOVE-CORRESPONDING itab1 TO itab2.
    APPEND itab2.
    DELETE itab1.
    ENDIF.
    AT NEW key.
    MOVE itab1-key TO lv_key.
    ENDAT.
    ENDLOOP.

    Regards

    Tamá

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jun 18, 2008 at 09:24 AM

    Hi Ching ,

    I dont know of any command which does it , one method i would suggest is to loop on the internal table and move the dupliacte records to anothe table.

    Regards

    Arun

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jun 18, 2008 at 09:25 AM

    Hi,

    you can use SORT statement and DELETE ADJACENT DUPLICATE statement.

    I hope this will help you.

    Help children of U.N World Food Program by rewarding them and encourage others to answer your queries.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jun 18, 2008 at 09:26 AM

    Hi,

    Loop at that internal table.Check whether 1st and second entry is same.If yes,move the 2nd entry to some internal table.Capture the table index of that record and delete it from the table.

    Otherwise,make use of this stmt:

    DELETE ADJACENT DUPLICATES FROM ITAB COMPARING <FIELD1>.

    write the logic as per requirement.Check whether you want to save duplicate records or delete them.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jun 18, 2008 at 09:27 AM

    Hi,

    Declare 2 ITAB'S. ITAB1 and ITAB2. if you have all the records in ITAB1 then move those records to table ITAB2. Now you can delete adjacent duplicates in ITAB2, since you are having only 1 field in your Internal Table.

    Regards,

    Viji.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jun 18, 2008 at 09:31 AM

    loop at itab.

    at new field 1.

    flag = 'x'.

    endat.

    if flag is initial.

    move itab to itab2.

    append itab2.

    endif.

    clear flag.

    endloop.

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.