To delete duplicate records from internal table

hi friends,
i have to delete records from internal table based on following criterion.
total fields are 7.
out of which  if 4 fields are same and 5th field is different,then both records must be deleted.
in case all five fields are same,the program should do nothing.
for example.
if there are 3 records as follows
a1 b1 c1 d1 e1 f g
a1 b1 c1 d1 e2 w r
a1 b1 c1 d1 e1 j l
then first two records should be deleted as four fields are same but fifth(e) field differs.
but third record should remain as it is evenif first five fields are same for first and third record.
values of last two fields need not to be consider for deleting the records.

LOOP AT ITAB.
  V_FILED5 = ITAB-F5. "to compare later
  V_TABIX = SY-TABIX. "used to delete if condition not matches
  READ TABLE ITAB WITH KEY F1 = ITAB-F1
                           F2 = ITAB-F2
                           F3 = ITAB-F3
                           F4 = ITAB-F4.
  IF SY-SUBRC = 0.
    IF ITAB-F5 <> V_FIELD5.
*--both the records to be deleted,as Field5 is different.
      DELETE ITAB INDEX SY-TABIX. "deletes that record
      DELETE ITAB INDEX V_TABIX. "deletes the current record
    ENDIF.
  ENDIF.
ENDLOOP.
Message was edited by: Srikanth Kidambi
added comments
Message was edited by: Srikanth Kidambi

Similar Messages

  • Unable to delete double records from internal table

    Hi all,
    The internal table is like this
    begin of ta_itab1 occurs 0,
          mark type c,
          cnt_hedg type c,
          kunnr like vbak-kunnr,
          vbeln like vbak-vbeln,
          posnr like vbap-posnr,
          matnr like vbap-matnr,
          kwmeng like vbap-kwmeng,
          h_kwmeng like vbap-kwmeng,
          spart like vbap-spart,
          werks like vbap-werks,
          component like bom_item_api01-component,
          comp_qty like bom_item_api01-comp_qty,
          comp_qty1 like bom_item_api01-comp_qty,
          base_quan like stko_api02-base_quan,
          comp_unit like bom_item_api01-comp_unit,
          base_unit like bom_item_api01-comp_unit,
          bukrs_vf like vbak-bukrs_vf,
          end of ta_itab1.
    and used the sytax:
    sort ta_itab6 by kunnr vbeln.
    DELETE ADJACENT DUPLICATES FROM ta_itab6 comparing COMP_QTY COMP_QTY1.
    but Im unable to delete duplicate record .
    Thank You.
    anu

    Hi ,
    You need to use the fields in sort statement on whichyiu wnat to perform Delete Adjacent duplicates..
    sort ta_itab6 by kunnr vbeln COMP_QTY COMP_QTY1.
    DELETE ADJACENT DUPLICATES FROM ta_itab6 comparing COMP_QTY COMP_QTY1.

  • Delete matching records from internal table

    I have two internal tables.
    say :
    1)zsd80
    2)i_vbrk
    i want to delete records from i_vbrk which are not in zsd80.
    this is my code. but it shows dump error after executing. please help.
    LOOP AT i_zsd80 INTO zsd80.
                LOOP AT i_konv INTO w_konv FROM w_index.
                  IF w_konv-kschl NE zsd80-kschl.
                    DELETE i_konv FROM w_konv.
                  ENDIF.
                ENDLOOP.
              ENDLOOP.

    Hi,
    Do like this...
    1. Loop at the where u want to delete..
    2. store the sy-index...
    3. read the other table....
    4. if nothing found  in read then delete that index...
    LOOP AT i_vbrk.
      TABIX = SY-TABIX.
      READ TABLE zsd80 WITH KEY .......
      IF SY-SUBRC NE 0.
        DELETE IT_VBRK INDEX TABIX.
      ENDIF.
    ENDLOOP.
    regards
    Sukriti.....
    Edited by: Sukriti Saha on Nov 3, 2008 1:19 PM

  • How to update Records from Internal table to u2018Zu2019 table?

    Hi Friends,
    How to update Records from Internal table to u2018Zu2019 table.
    I have records in Internal table , that records want to update on u2018Zmarau2019 Table.
    ( my internal table & u2018 Zu2019 table structures are same.)
    Thanking you.
    Regards,
    Subash

    Hi,
    loop at internal table.
    modify <Z- table > from values < internal table Workarea>.
    if sy-subrc = 0.
      COMMIT work.
    else.
      ROLLBACK waork.
    endif.
    endloop.
    or
    UPDATE <Z- table > from table < internal table Workarea>.
    if sy-subrc = 0.
      COMMIT work.
    else.
      ROLLBACK waork.
    endif.
    Prabhudas

  • Inserting records from internal table to database table

    Hi all,
    i want to insert records from internal table to zDatabase table, can u plz guide me which statement is better in performance to insert the records.
    1) insert one by one record from internal table
    loop at itab.
    insert ztable from wa.
    endloop.
    2) insert total records at a time
    INSERT <dbtabname> CLIENT SPECIFIED FROM TABLE itab.
    or let me know if any other statement is there with high performance.
    i internal table contains nearly 40000 records.
    thanks.

    Hi,
    Insert the entire table at atime rather than a record so as to increase the performance.
    you can use INSERT <dbtabname> CLIENT SPECIFIED FROM TABLE itab.
    or
    MODIFY ZPRODUCT FROM TABLE GI_AFPO.
    Regards,
    Raj.

  • How to delete a record from BSEG table

    Dear Experts,
    How to delete a record from BSEG table.
    If there possible to delete some records from transparent table ?
    Please help.
    Regards,
    Tan

    Hi,
    Deleting a record from a standard table can be done only if table maintenance exists - Cehck tcode - SM30.  But it is not advisable to delete records, coz the records may be dependent on many other tables.  If u delete in a single place, there may be chance that inconsistency in the data happens and hence will affect ur financial statements.
    Pls. assign points, if useful
    Regards,
    Sridevi

  • Delete a record from a table in a Database with Database Connectivity

    I can't find the function from the Database Connectivity library that allows me to delete a record from a table of the database. I tried to use DB Tools Free Object.vi function but this one deletes only the table created with a query.
    Thankyou

    I have used the sql query as described above and it works fine with access DB and the DB toolkit, the free object vi only deallocated a recordset's references this will noty alter the database since the record is a copy of the databases information.  The SQL delete function is very versatile and you should be able to delete records with no problem.
    Paul
    Paul Falkenstein
    Coleman Technologies Inc.
    CLA, CPI, AIA-Vision
    Labview 4.0- 2013, RT, Vision, FPGA

  • Is it safe to purge / delete older records from AUD$ table in SYS schema

    Hi,
    Can we purge / delete older records from AUD$ table in SYS schema.
    Please advice.
    Thanks
    Naveen

    Pl see MOS Doc 73408.1 (How to Truncate, Delete, or Purge Rows from the Audit Trail Table SYS.AUD$) fro details on how to do so.
    HTH
    Srini

  • 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

  • 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.

  • Regarding how to delete the record in internal table

    Hi experts ,
    how to delete the record in intarnal table after validating the data,
    if record contains invalid fields?
    i am giving my code see this and give me the answer?
    loop at it_data into wa_data .
    Validate  Cost Center
        READ TABLE it_kostl INTO wa_kostl WITH KEY kostl = wa_data-kostl BINARY SEARCH.
        IF sy-subrc NE 0.
          PERFORM update_error_log USING wa_data
                                         text-004.
        ENDIF.
    Validate source file material ( material number )
    loop at it_mara into wa_mara .
      read table it_ausp into wa_ausp with key atwrt = wa_data-i_matnr .
               if sy-subrc NE 0 .
       PERFORM update_error_log USING wa_data
                                           text-002.
    delete it_data-objek .
         else.
      read table it_mara into wa_mara with key  matnr = wa_ausp-objek .
           if sy-subrc EQ 0 .
           wa_data-objek = wa_mara-matnr.
           wa_data-matkl = wa_mara-matkl.
         ENDIF.
         Modify it_data from wa_data  .
      endif.
    *endloop.
    Validate unit of measure (unit)
        READ TABLE it_t006 INTO wa_t006 WITH KEY msehi = wa_data-unit .
        IF sy-subrc NE 0.
          PERFORM update_error_log USING wa_data
                                         text-003.
        endif.
    Validate delivery location ( storage location )
        READ TABLE it_lgort INTO wa_lgort WITH KEY del_loc = wa_data-del_loc.
        IF sy-subrc NE 0.
          PERFORM update_error_log USING wa_data
                                         text-001.
             if wa_data-flag ='x' .
          delete it_data from  wa_data .
        endif.
        ENDIF.
    endloop.

    Hi Naren,
    First get the index number of the IT_data table and store it in one variable whose declaration like this.
    data: tabix type sy-tabix.
    while reading the internal table it_data set the tabix variable.
    tabix = sy-tabix.
    Instead of  the above use below one.
    Delete it_data-objek
    Use the Below statement it will delete  the row from the internal table.
    Delete it_data-objek index tabix
    Thanks,
    Chidanand

  • Deleting Duplicate entries from Internal tbale

    Hi All,
    I have used this code to delete duplicate entries from an internal table.
      DELETE ADJACENT DUPLICATES FROM IT_KOSTL COMPARING KOSTL hours.
    After this statment, still the internal table will remain with a duplicate row.
    Earlier table content before the delete statement:
    Lno  KOSTL                PRCTR                       hours                      hours1 
    1    2081010205     0000208101                 5525.000          1574.500
    2    2081010105     0000208101       105162.000     73854.750
    3    2081010105     0000208101       105162.000     73854.750
    4    2081010205     0000208101        5525.000     1574.500
    The Table gets modified after execution of DELETE statement as follows.
    Lno  KOSTL                PRCTR                       hours                      hours1 
    1    2081010205     0000208101                 5525.000          1574.500
    2    2081010105     0000208101       105162.000     73854.750
    3    2081010205     0000208101        5525.000     1574.500
    Why the line 3 is still present in the table?
    I hope as per that syntax, this line too should get delete.... Is it right?
    Basically i would like to delete both line 3 and line 4 from....
    How to resolve this issue?
    Please help me out....
    Regards
    Pavan
    What might be the reason?

    >
    Pavan Sanganal wrote:
    >   DELETE ADJACENT DUPLICATES FROM IT_KOSTL COMPARING KOSTL hours.
    > Why the line 3 is still present in the table?
    >
    > I hope as per that syntax, this line too should get delete.... Is it right?
    >
    Let me answer you all doubts.
    Why the line 3 is still present in the table?
    Actually it's not 3rd line, it's 2nd line.3rd line were deleted.
    when delete adjecent duplicates trigger than it would delete lower line(3rd in your case) not upper line.
    I hope as per that syntax, this line too should get delete.... Is it right?
    NO.

  • Deleting duplicate records from different data packets in BI data source.

    Hi,
    I am getting same (duplicate) records from different data packets in BI data source, after completion of extraction.
    I tried to store key fields of the first data packet in an internal table. But this internal table is not carrying the previous data at the time of extraction of second data packet.
    Is there any other way to remove duplicate records after completion of extraction.
    Thanks in advance.

    I did not extensively worked in BI routenes. But I recon there will be routene which will het executed before data mapping part there will be a start routene in which you can validate the existense of data before beeing passed from data source to cube.
    Hope this helps,
    Regards,
    Murthy.

  • To get recent timestamp records from internal table

    hi all,
      i have one requirment
      i'm storing error messages in one table  while creating a sales order basing on timestamp
      which is of this format yyyy-mm-dd hh:mm:ss (random Number) 
      if i want to see the error messages left i'm getting all the error messages displayed
      for example i have created a sales order
    i got 10 errors displayed
    i have rectified 5 errors ... if i again display error messages the 10 errors + the 5 errors is getting displayed
    i want to display the 5 error messages only not the previous messages from internal table
    basing on timestamp current one has to displayed remaining has to deleted from internal table.

    I thought we used Sales Order Incompletion process for this....  but, if you're recreating the errors list every time you save with a create or change transaction then, at save, delete all rows in your error table for this document.   Then get your errors and update your db table from your current errors table.   From this viewpoint, the timestamp is not relevant.

  • Importing and Updating Non-Duplicate Records from 2 Tables

    I need some help with the code to import data from one table
    into another if it is not a duplicate or if a record has changed.
    I have 2 tables, Members and NetNews. I want to check NetNews
    and import non-duplicate records from Members into NetNews and
    update an email address in NetNews if it has changed in Members. I
    figured it could be as simple as checking Members.MembersNumber and
    Members.Email against the existance of NetNews.Email and
    Members.MemberNumber and if a record in NetNews does not exist,
    create it and if the email address in Members.email has changed,
    update it in NetNews.Email.
    Here is what I have from all of the suggestions received from
    another category last year. It is not complete, but I am stuck on
    the solution. Can someone please help me get this code working?
    Thanks!
    <cfquery datasource="#application.dsrepl#"
    name="qryMember">
    SELECT distinct Email,FirstName,LastName,MemberNumber
    FROM members
    WHERE memberstanding <= 2 AND email IS NOT NULL AND email
    <> ' '
    </cfquery>
    <cfquery datasource="#application.ds#"
    name="newsMember">
    SELECT distinct MemberNumber
    FROM NetNews
    </cfquery>
    <cfif
    not(listfindnocase(valuelist(newsMember.MemberNumber),qryMember.MemberNumber)
    AND isnumeric(qryMember.MemberNumber))>
    insert into NetNews (Email_address, First_Name, Last_Name,
    MemberNumber)
    values ('#trim(qryMember.Email)#',
    '#trim(qryMember.FirstName)#', '#trim(qryMember.LastName)#', '#
    trim(qryMember.MemberNumber)#')-
    </cfif>
    </cfloop>
    </cfquery>
    ------------------

    Dan,
    My DBA doesn't have the experience to help with a VIEW. Did I
    mention that these are 2 separate databases on different servers?
    This project is over a year old now and it really needs to get
    finished so I thought the import would be the easiest way to go.
    Thanks to your help, it is almost working.
    I added some additional code to check for a changed email
    address and update the NetNews database. It runs without error, but
    I don't have a way to test it right now. Can you please look at the
    code and see if it looks OK?
    I am also still getting an error on line 10 after the routine
    runs. The line that has this code: "and membernumber not in
    (<cfqueryparam list="yes"
    value="#valuelist(newsmember.membernumber)#
    cfsqltype="cf_sql_integer">)" even with the cfif that Phil
    suggested.
    <cfquery datasource="#application.ds#"
    name="newsMember">
    SELECT distinct MemberNumber, Email_Address
    FROM NetNewsTest
    </cfquery>
    <cfquery datasource="#application.dsrepl#"
    name="qryMember">
    SELECT distinct Email,FirstName,LastName,MemberNumber
    FROM members
    WHERE memberstanding <= 2 AND email IS NOT NULL AND email
    <> ' '
    and membernumber not in (<cfqueryparam list="yes"
    value="#valuelist(newsmember.membernumber)#"
    cfsqltype="cf_sql_integer">)
    </cfquery>
    <CFIF qryMember.recordcount NEQ 0>
    <cfloop query ="qryMember">
    <cfquery datasource="#application.ds#"
    name="newsMember">
    insert into NetNewsTest (Email_address, First_Name,
    Last_Name, MemberNumber)
    values ('#trim(qryMember.Email)#',
    '#trim(qryMember.FirstName)#', '#trim(qryMember.LastName)#', '#
    trim(qryMember.MemberNumber)#')
    </cfquery>
    </cfloop>
    </cfif>
    <cfquery datasource="#application.dsrepl#"
    name="qryEmail">
    SELECT distinct Email
    FROM members
    WHERE memberstanding <= 2 AND email IS NOT NULL AND email
    <> ' '
    and qryMember.email NEQ newsMember.email
    </cfquery>
    <CFIF qryEmail.recordcount NEQ 0>
    <cfloop query ="qryEmail">
    <cfquery datasource="#application.ds#"
    name="newsMember">
    update NetNewsTest (Email_address)
    values ('#trim(qryMember.Email)#')
    where email_address = #qryEmail.email#
    </cfquery>
    </cfloop>
    </cfif>
    Thank you again for the help.

Maybe you are looking for

  • Links to PDF files with relative paths from a Captivate 4 project

    I'm creating a presentation in Captivate 4 (I'm making an exe file) with some links to PDF files; the links are buttons with the 'open URL or file' set. The presentation will be distributed in CDs and obviously the links will not work for they point

  • How to recover from Large Volume Table Insert

    We are inserting 1 Million rows into table using ODI IKM Append. If half the way thru the job fails because of tablespace or other issue, how to recover? Does 50% rows are commited to db? What is the best way to handle this type of situation?

  • Customers RFC TO PI

    Hi!   I have a ABAP to send the Custumers Data to External System by PI.   CALL FUNCTION 'YMC1_RFC_CARGA_CLIENTES_DUMMY'     DESTINATION 'ECC_TO_PI'     TABLES       in_t_clientes           = p_in_t_clientes       in_t_clientecomplemento = p_in_t_cli

  • WRT610N and PS3 - Slow audio and photo streaming, while video is fine

    Hi, I just hooked up my USB portable hard drive to this Linksys router and was able to access the picture/audio/video on my PS3, it's very cool  However I quickly noticed is has couple of problems: The access to JPG files is painfully slow, on averag

  • Partial string replacement

    Let's say I have an XML variable like the following: <AWARDS d-type="String">Booklist 2002 - Twenty Best Bets for Student Researchers | IHOP Best Reads While Consuming Far Too Much Coffee 2002</AWARDS> and I want to replace the | with <br> when the v