How to choose in Delete Duplicates from internal table?

Now I need to delete Duplicates from internal table,
So at first I sort
than I delete duplicate
Sort itab1 BY Company_Code  Asset_No Capital_Date.
      DELETE ADJACENT DUPLICATES FROM itab1 COMPARING Company_Code  Asset_No  Capital_Date
Company_Code
Asset_No
Capital_Date
Remark
BC35
1515593
20021225
Helen
BC35
1515593
20021225
Common Asset
BC35
1515594
20030109
Judy
BC35
1515594
20030109
Common Asset
But here comes my problem~If I want to delete the Common Asset in Remark Column,how I let it choose the right one to do it?

Hi Jack
Try the below coding..
Report zsamp.
types: begin of t_tab,
        comp_code(4) type c,
        ***_no(7) type n,
        cap_date type d,
        remark type string,
        end of t_tab.
data: i_tab type TABLE OF t_tab,
       w_tab type t_tab.
w_tab-comp_code = 'BC35'.
w_tab-***_no = '1515593'.
w_tab-cap_date = '20021225'.
w_tab-remark = 'Helen'.
append w_tab to i_tab.
w_tab-comp_code = 'BC35'.
w_tab-***_no = '1515593'.
w_tab-cap_date = '20021225'.
w_tab-remark = 'Common Asset'.
append w_tab to i_tab.
w_tab-comp_code = 'BC35'.
w_tab-***_no = '1515594'.
w_tab-cap_date = '20030109'.
w_tab-remark = 'Judy'.
append w_tab to i_tab.
w_tab-comp_code = 'BC35'.
w_tab-***_no = '1515594'.
w_tab-cap_date = '20030109'.
w_tab-remark = 'Common Asset'.
append w_tab to i_tab.
sort i_tab by remark.
delete ADJACENT DUPLICATES FROM i_tab COMPARING remark.

Similar Messages

  • Delete Duplicates from internal table with object references

    Hi
    How can I delete duplicates from an internal table in ABAP OO based on the value of one of the attributes?
    I have created a method, with the following code:
      LOOP AT me->business_document_lines INTO l_add_line.
        CREATE OBJECT ot_line_owner
          EXPORTING
            i_user      = l_add_line->add_line_data-line_owner
            i_busdoc = me->business_document_id.
          APPEND ot_line_owner TO e_line_owners.
      ENDLOOP.
    e_line_owners are defined as a table containing only object references.
    One of the attribute of the object in the table is called USER. And I would like to do a "delete ADJACENT DUPLICATES FROM e_line_owners", based on that attribute.
    How can do this?
    Regards,
    Morten Nielsen

    Hello Morten
    Assuming that the instance attribute is <b>public </b>you could try to use the following coding:
      SORT e_line_owners BY table_line->user.
      DELETE ADJACENT DUPLICATES FROM e_line_owners
        COMPARING table_line->user.
    However, I am not really sure (cannot test myself) whether <b>TABLE_LINE</b> can be used together with SORT and DELETE.
    Alternative solution:
      DATA:
         ld_idx    TYPE sy-tabix.
      LOOP AT e_line_owners INTO ls_line.
        ld_idx = syst-tabix + 1.
        LOOP AT e_line_owners TRANSPORTING NO FIELDS FROM ld_idx
                       WHERE ( table_line->user = ls_line->user ).
          DELETE e_line_owners INDEX syst-tabix.
        ENDLOOP.
      ENDLOOP.
    Regards
      Uwe

  • Delete duplicate from internal table

    HI Abapers,
    I have a query on how to remove the duplicates from an internal table
    My internal table data is as follows :
    Cno    Catg1  Catg2
    01       0         1000
    01      2000         0
    I want to get only one record as
    01   2000  1000
    How to  get the result.
    I tried sorted by cno and used delete duplicates but it was not helpful.
    Is there any other alternative to get this done
    Please help me.
    Regards,
    Priya

    check it out with delete adjacent duplicate records
    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.

  • Deleting Duplicates from a table

    Its a huge table with 52 fields and 30k rows. I need to delete the duplicates based on one of the fields. GROUP BY is taking a lot of time. Is there a quicker way to delete the duplicates using SQL.
    Thanks.

    How many duplicates have you got? Do you have even a vague idea? 1%? 20%? 90%?
    One way would be to add a unique constraint on the column in question. This will fail, of course, but you can use the EXCEPTIONS INTO clause to find all the ROWIDs which have duplicate values. You can then choose to delete those rows using a variant on teh query already posted. You may need to run %ORACLE_HOME%\rdbms\admin\utlexcptn.sql to build the EXCEPTIONS table first.
    This may seem like some unnecessary work, but the most effective way of deleting duplicates from a table is to have relational integrity constraints in place which prevent you having duplicates in the first place. To paraphrase Tim Gorman, you can't get faster than zero work!
    Cheers, APC

  • Deleting entry from internal table

    Hi Experts,
    i have the following internal table:
    data :    it_result1            TYPE   crmt_object_guid_tab
    and work area
    data : wa_result1 type crmt_object_guid.
    i have to delete a guid from internal table based on some condition.
    loop at it_resul1 into wa_result1
    if lv_priority eq priority.
    delete     this entry from internal table.
    endif.
    endloop..
    i tried using  delete table it_result with table key CRMT_OBJECT_GUID = wa_result. but this is giving syntax error.
    what should be done to delete the entry?
    Thanks and regards
    Shilpi

    Hi
    Check Syntax for DELETE operator on pressing F1
    1. DELETE itab.
    2. DELETE TABLE itab WITH TABLE KEY k1 = v1 ... kn = vn.
    3. DELETE TABLE itab [FROM wa].
    4. DELETE itab INDEX idx.
    5. DELETE itab FROM idx1 TO idx2.
    6. DELETE itab WHERE logexp.
    7. DELETE ADJACENT DUPLICATES FROM itab.
    delete table it_result with table key CRMT_OBJECT_GUID = wa_result
    this is wrong
    delete  it_result where CRMT_OBJECT_GUID = wa_result
    Edited by: Lavanya K on Apr 22, 2009 10:20 AM

  • Delete records from internal table

    hi all,
    i want to delete records from intenal table which are starting with a particular starting number .
    eg internal table
    10000
    20000
    90000
    91000
    92000
    88880
    i want delete the records starting with 9 i.e. 90000 91000 92000.
    Thanks in Adv
            RAJ

    You can test this piece of code.
    DATA:
    i_tab TYPE STANDARD TABLE OF mara,
    wa_tab TYPE mara.
    wa_tab-matnr = '1000'.
    APPEND wa_tab TO i_tab.
    CLEAR wa_tab.
    wa_tab-matnr = '1001'.
    APPEND wa_tab TO i_tab.
    CLEAR wa_tab.
    wa_tab-matnr = '1002'.
    APPEND wa_tab TO i_tab.
    CLEAR wa_tab.
    wa_tab-matnr = '1003'.
    APPEND wa_tab TO i_tab.
    CLEAR wa_tab.
    wa_tab-matnr = '2001'.
    APPEND wa_tab TO i_tab.
    CLEAR wa_tab.
    wa_tab-matnr = '3001'.
    APPEND wa_tab TO i_tab.
    CLEAR wa_tab.
    wa_tab-matnr = '4010'.
    APPEND wa_tab TO i_tab.
    CLEAR wa_tab.
    <REMOVED BY MODERATOR>
    Edited by: Alvaro Tejada Galindo on Aug 8, 2008 4:49 PM

  • Duplicates From Internal Tabl

    Hello,
    I have an internal table with 6 fields and if the first five fields are same then its called a dublicate and I shud collect these duplicates in an other table moving the original to the other internal table. So from the basic Internal table I need to form 2 tables one with originals and the other with duplicates..How do i do this?
    Thanks
    Viky

    Hi
    Say itab is your first table and
        itab2 is table of the same type as itab
    wa_itab and wa_itab are work areas of the type of your internal table.
    Loop at itab into wa_itab.
    clear cnt.
    Loop at itab into wa_itab1 where field1 = wa_itab-field1
                                                   field2 = wa_itab-field2
                                                   field3 = wa_itab-field3
                                                   field4 = wa_itab-field4
                                                   field5 = wa_itab-field5
    cnt = cnt + 1.
    If cnt gt 1.
    append wa_itab1 to itab2.
    DELETE itab from wa_itab1.
    endif.
    Endloop.

  • Reg deleting entries from internal table

    Hi experts,
       I have two internal tables , ITAB1 and ITAB2 (same structure), i like to delete the records from ITAB1 which are in ITAB2 without looping .How it can be done?
    regards,
    Kannan

    Lozan,
    itab1 is having 1,2,3,4.
    itab2 is having 1,2,5,6,7.
    Now I move the contents in itab1 and itab2 to itab3.
    itab3 is having now 1,2,3,4,1,2,5,6,7.
    Now I will sort this itab3,thus itab3 is now having
    1,1,2,,2,3,4,5,6,7.
    <b>Now,if  I use delete adjacent duplicates from itab3,will it won't result in
    1,2,3,4,5,6,7 in itab3?</b>
    K.Kiran.
    Message was edited by:
            Kiran K
    Message was edited by:
            Kiran K

  • Deleting duplicates from a table ,who's size is 386 GB

    Need to delete duplicate records from the table.Table contains 33 columns out of them only PK_NUM is the primary key columns. As PK_NUM contains unique records we need to consider either min/max value.
    Sample data :
    PK_NUM
    Name
    AGE
    1
    ABC
    20
    2
    PQR
    25
    3
    ABC
    20
    Expected data should contains only 2 records:
    PK_NUM
    Name
    AGE
    1
    ABC
    20
    2
    PQR
    25
    *1 can be replaced by 3 ,vice versa.
    Size of table : 386 GB
    Total records in the table : 1766799022
    Distinct records in the table : 69237983(Row distinct with out Primary key)
    Duplicate records in the table : 1697561039(Row duplicates without primary key)
    Column details :
    4 :  Date data type
    4 :  Number data type
    1 :  Char data type
    24:  Varchar2 data type
    DB details : Oracle Database 11g EE::11.2.0.2.0 ::64bit Production
    My plan here is to
    Pull distinct records and store it in a back up table.(ie by using insert into select)
    Truncate existing table and move records from back up to existing.
    As data size is huge ,
    Want to know what is the optimized sql for retrieving the distinct records
    Any estimate on how much it will take to complete (insert into select) and to truncate the existing table.
    Please do let me know ,if there is any other best way to achieve this.My ultimate goal is to remove the duplicates.

    As data size is huge ,
    Want to know what is the optimized sql for retrieving the distinct records
    Any estimate on how much it will take to complete (insert into select) and to truncate the existing table.
    @ 1. - Your best chance seems to be (should require a single FTS only)
    create backup_table as
    select pk,name,age,a_date,a_string,a_number, ...
      from (select pk,name,age,a_date,a_string,a_number, ...
                   row_number() over (partition by name,age order by a_date) rn
              from big_table
    where rn = 1
    @ 2. - Having statistics in place and (at least nearly) up to date explain plan should return an appropriate estimate
    Regards
    Etbin
    select pk,name,age,a_date,a_string,a_number
      from (select pk,name,age,a_date,a_string,a_number,
                   row_number() over (partition by name,age order by a_date) rn
              from big_table
    where rn = 1
    Operation
    Options
    Object
    Rows
    Time
    Cost
    Bytes
    Filter
    Predicates *
    Access
    Predicates
    SELECT STATEMENT 
    13,044
    1
    30
    53,023,860
    VIEW
    13,044
    1
    30
    53,023,860
    "RN" = 1
    WINDOW
    SORT PUSHED RANK
    13,044
    1
    30
    495,672
    ROW_NUMBER() OVER ( PARTITION BY "NAME","AGE" ORDER BY "A_DATE")< = 1
    TABLE ACCESS
    STORAGE FULL
    BIG_TABLE
    13,044
    1
    26
    495,672
    select pk,name,age,a_date,a_string,a_number
      from big_table
    where pk in (select min(pk) keep (dense_rank first order by a_date)
                    from big_table
                   group by name,age
    Operation
    Options
    Object
    Rows
    Time
    Cost
    Bytes
    Filter
    Predicates *
    Access
    Predicates
    SELECT STATEMENT 
    6,000
    1
    52
    306,000
    HASH JOIN
    6,000
    1
    52
    306,000
    "PK" = "$kkqu_col_1"
    VIEW
    VW_NSO_1
    6,000
    1
    27
    78,000
    HASH
    UNIQUE
    6,000
    1
    27
    126,000
    SORT
    GROUP BY
    6,000
    1
    27
    126,000
    TABLE ACCESS
    STORAGE FULL
    BIG_TABLE
    13,044
    1
    23
    273,924
    TABLE ACCESS
    STORAGE FULL
    BIG_TABLE
    13,044
    1
    24
    495,672
    Message was edited by: Etbin

  • Problem in deleting entries from internal table

    i am selecting
               vrgar
                perio
                paobjnr
                belnr
                gjahr
                perde
                budat
                kndnr
                artnr
                frwae
                kursf
                rec_waers
                kaufn
                kdpos
                bukrs
                kokrs
                werks
                gsber
                vkorg
                vtweg
                spart
                rbeln
                rposn
                prctr
                pprctr
                kunnr
                land1
                regio
                kunwe
                kvgr1
                wwpmg
                zterm
                wwcst
                wwrst
                mvgr3
                wwseg
                wwcls
                wwesa
                prdha
                wwbun
                wwexd
                wwph1
                wwph2
                wwph3
                wwph4
                prat1
                prat2
                vrprs
                vv510
                vv508
                vv509
                vvqt2
                vv515
        INTO TABLE ct_ce11000 FROM ce11000
        WHERE paledger EQ gv_ledbo AND
              vrgar    EQ lc_vrgar AND
              belnr    GT uv_belnr AND
              gjahr    EQ pa_gjahr AND
              perde    EQ pa_perd AND
              bukrs    EQ pa_bukrs.
    now i awant to delete all those entries from my internal table ct_ce11000 where my plant (WEKRS) and company code (BUKRS)
    i am writting
    loop at ct_ce11000 into wa_ce11000.
    if wa_ce11000-werks ne wa_ce11000-bukrs.
    now how can i delete all the entries from nmy internal table (ct_ce11000)  when plant and company code is not same
    pls help me  with logic.
    thank you for helping me

    Hello Guys,
    It is not advisable to delete the entries from the internal table you are looping upon. See this thread: [Sy-tabix in loop : Doubt|Sy-tabix in loop : Doubt]
    And to answer the OP's question select data into some local internal table & based on the condition populate your final table. Creating a local table of the same type as the final table will not create too much performance overhead
    Cheers,
    Suhas

  • DELETED rows from internal table

    Hi Experts,
    If I delete row/s from an internal table
    using the command DELETE ADJACENT DUPLICATES,
    is there a way to get these deleted rows.
    Thanks in advance.
    Rose

    Hi roselie,
    1. ofcourse not.
    2.hence, before that,
      u can declare another internal table,
      similar to original,
      and use like this.
    3. ITAB1[]   = ORIGINALITAB[].
    regards,
    amit m.

  • Deleting block from internal table with AT / ENDAT

    Hi.
    I have the following code:
    sort itab by pred_doc.
    loop at itab into wa_cust.
    At end of pred_doc.
    sum.
    write :/ wa_cust-pred_doc, wa_cust-amount.
    if wa_cust-amount = 0.
    Delete entire block of this pred_doc
    endif.
    endat.
    endloop.
    Within that "IF" statement, I want to delete the entire block (all entries with that pred_doc).  How do I do this?  I'm not sure of the syntax.  In other words, I just need to do subtotals of the internal table by pred_doc on amount.  If the subtotal equals zero, the records for that pred_doc need to be removed from the internal table. 
    Thanks,
    Clay

    Hi,
    I agree with Rob. Use two internal tables for this purpose.
    data: itab1 like itab. New internal table which will hold the required entries
    sort itab by pred_doc.
    loop at itab into wa_cust.
    At end of pred_doc.
    sum.
    write :/ wa_cust-pred_doc, wa_cust-amount.
    if wa_cust-amount ne 0. " If the workarea has the subtotal entry with amount not equal to zero, then transfer it to a new internal table
    append wa_cust to itab1
    endif.
    endat.
    endloop.
    Now itab1 will contain your required entries. But please note that this will be the 'summed up' entries and not the the individual entries before summing up.
    Hope this helps!
    Cheers,
    Mahesh

  • Delete lines from internal table

    Hello experts!
    I have two internal tables.
    select options sa_tknr and gt_versand_plan.
    sa_tknr-low contents transportation-Nr.
    gt_versand_plan has transportation-Nr too (gt_versand_plan-tknum).
    How can I delete all transportation-Nr from
    gt_versand_plan which dont' appear in sa_tknr-tknum.
    THX
    sas

    Hi
    check this statement.
    <b>delete gt_versand_plan where not tknum in sa_tknr.</b>
    <b>Reward points for useful Answers</b>
    Regards
    Anji

  • Delete row from internal table using field symbol.

    Hi friends,
      I created dynamic internal table using field symbol. I want to delete some data using where clause.
    for example. i want to use like,
        DELETE <FS> WHERE KUNNR = WA_KNA1-KUNNR.
    Like the above statment it won't work. How i can use delete with where clause in field symbols.
    Hope any one can help me.
    Thanks and regards
    Srikanth. S

    hi Srikanth,
    I think you have to LOOP through the whole internal table and check each line and decide to delete or not:
    LOOP at <itab> INTO <wa>.
    ASSIGN COMPONENT 'KUNNR' OF STRUCTURE <wa> TO <field>.
    CHECK <field> IS ASSIGNED.
    IF <field> EQ WA_KNA1-KUNNR.
    DELETE ...
    ENDIF.
    UNASSIGN <field>.
    ENDLOOP.
    hope this helps
    ec

  • Delete records from internal table using another internal table

    HI,
    I have two internal tables itab1 and itab2 which have same records initially.Later some records of itab2 are deleted .Then i want to delete those records from itab1 also ie,those records not found in itab2 .Is there any method other than looping.
    So that itab1 again becomes equal to itab2.
    Thanks in advance.
    Sowmya.

    Soumya,
    Itab1 , Itab2 .
    Before deleting the records from itab2  move those records to one more internal table itab3.
    Now you have deleted records  of itab2  in itab3.
    SORT ITAB3,ITAB1 by your main key field.
    LOOP AT itab3.
      READ TABLE ITAB1 WITH KEY key field = itab3-
      keyfield.
    IF sy-subrc EQ 0.
    DELETE itab1 where keyfield eq itab3-keyfield.
    ENDIF.
    ENDLOOP.

Maybe you are looking for

  • IPOD Mini is not recognized by my PC

    Help! I can't restore/update my Ipod Mini because my PC won't recognize it. When I reset the Ipod I get a folder/! or an Apple symbol - nothing more. The computer seems to be able to charge the Ipod, but doesn't recognize it - doesn't start Itunes, s

  • How to view an Image in ABAP Webdynpro on button action

    Hi Experts, I want to view an image on a button action without creating a new view or window. I just need to display the image. Thanks, R Sahu

  • How to display thumbnail image of file in KM navigation layout

    Hi, I'm using a km nav iview to display some files to my users.  The files are all images and it would be more useful if the images could be displayed right upfront instead of clicking on the file name and having the page reload with preview.  I am a

  • Many problems after last update

    Ok, I will tell my actions step by step, because this update and my Arch now = big mess. I started the update (yaourt -Syu) in the end of January. Because my internet connection is not always working properly, I have to repeat this many times to star

  • Volume manage rootdg create problem

    Hi, all I used dd copy a disk with Veritas Volume Manager(VxVM) software packag on it to a new disk, after that, I use new disk to boot system (sparc-10), get messages like that : Aug 27 05:38:00 vxvm:vxconfigd: enable failed: Error in disk group con