8 Replies Latest reply: Apr 17, 2008 7:08 PM by Greg Kern RSS

DELETE ADJACENT DUPLICATES FROM itab comparing f1 f2 f3

Currently Being Moderated

Hi,

 

I have an ABAP internal table with four fields f1 f2 f3 f4 that i am deleting adjacent duplicates from.  However for each line that i delete i wish to know how many lines were deleted (i.e. how many f4's there were).  Anyone know how i could code this?

 

for example i initially have :

 

f1      f2      f3      f4

data  gad   fsd    vsds

data  gad   fsd    gdfgf

faff    gfg    gdg   fsgs

 

after that i have

 

f1      f2      f3      f4     count

data  gad   fsd    vsds  2

faff    gfg    gdg   fsgs   1

 

 

Basically i want to delete the extra rows but know how many were deleted via some sort of count applied to the itab before the DELETE ADJACENT DUPLICATES FROM itab comparing f1 f2 f3 statement.  Any help would be much appreciacted.

  • Re: DELETE ADJACENT DUPLICATES FROM itab comparing f1 f2 f3
    Paul Chapman
    Currently Being Moderated

    Unless you want to know how many of each type was deleted, you can use DESCRIBE TABLE it_table lines linecount, before and after your DELETE line.  Subtract the two values and you'll have the result.

    • Re: DELETE ADJACENT DUPLICATES FROM itab comparing f1 f2 f3
      Currently Being Moderated

      Hi,

       

      Thanks for that - i think i will need to use some sort of describe but i will have many rows in the table that have been collected - sorry my example was a little short.  So basically i need to know the count FOR EACH row that is summed.  Thanks

       

      A better one would be :

       

      f1 f2 f3 f4

      data gad fsd vsds

      data gad fsd gdfgf

      faff gfg gdg fsgs

      sds  fsf  fsfsf  fsfs

      sds  fsf  fsfsf  dgs

       

      becomes

       

      f1 f2 f3 f4 count

      data gad fsd vsds 2

      faff gfg gdg fsgs 1

      sds  fsf  fsfsf  fsfs 2

      • Re: DELETE ADJACENT DUPLICATES FROM itab comparing f1 f2 f3
        Anup Kumar
        Currently Being Moderated

        hi samir,

         

        You can use collect statement inside the loop for summarised output.

         

        for exmaple:

           

        TYPES: BEGIN OF COMPANY, 
                NAME(20) TYPE C, 
                SALES    TYPE I, 
              END OF COMPANY. 
        
        DATA: COMP    TYPE COMPANY, 
              COMPTAB TYPE HASHED TABLE OF COMPANY 
                                        WITH UNIQUE KEY NAME. 
        
        COMP-NAME = 'Duck'.  COMP-SALES = 10. COLLECT COMP INTO COMPTAB. 
        COMP-NAME = 'Tiger'. COMP-SALES = 20. COLLECT COMP INTO COMPTAB. 
        COMP-NAME = 'Duck'.  COMP-SALES = 30. COLLECT COMP INTO COMPTAB. 
        
        
        
        Table COMPTAB now has the following contents: 
        
                  NAME    | SALES 
                  --------------- 
                  Duck    |   40 
                  Tiger   |   20

         

  • Re: DELETE ADJACENT DUPLICATES FROM itab comparing f1 f2 f3
    Ravi Kanth Talagana
    Currently Being Moderated

    Do like this.

     

    • Make sure that your count is numeric type

     

    loop at itab.

    collect itab to itab_new.

    endloop.

     

    *itab and itab_new are of same type and itab_new should have the count

     

    Regards,

    Ravi Kanth Talagana

     

    Edited by: Ravi Kanth Talagana on Apr 17, 2008 6:15 PM

  • Re: DELETE ADJACENT DUPLICATES FROM itab comparing f1 f2 f3
    krishna chaitanya nanduri
    Currently Being Moderated

    Hi Samir,

     

    you can do one thing.check the following program

     

    REPORT  zchaitu_report5.

     

    data:begin of itab occurs 0,

         f1 type i,

         f2 type i,

         end of itab.

     

    data:c1 type i,

         c2 type i.

    itab-f1 = 1.itab-f2 = 2.append itab.

    itab-f1 = 1.itab-f2 = 1.append itab.

    itab-f1 = 2.itab-f2 = 3.append itab.

     

    loop at itab.

    c1 = c1 + 1.

    endloop.

    sort itab.

    delete adjacent duplicates from itab comparing f1.

    loop at itab.

    c2 = c2 + 1.

    endloop.

    write: / c1,c2.

     

    c1 is the no of records before deletion,c2 is the no of records after deletion.difference between c1 and c2 is the no of records deleted.

  • Re: DELETE ADJACENT DUPLICATES FROM itab comparing f1 f2 f3
    Currently Being Moderated

    The crucial thing that i need is the NUMBER OF LINES WITH WHICH f1 f2 and f3 are equal FOR EACH ROW.  Hope that clarifies what i need... Thanks,

     

    Samir

  • Re: DELETE ADJACENT DUPLICATES FROM itab comparing f1 f2 f3
    Greg Kern
    Currently Being Moderated

    Hello

     

    Ravi has given you a good solution as per below.

     

    ****************

    Do like this.

     

     

    Make sure that your count is numeric type

     

    loop at itab.

    collect itab to itab_new.

    endloop.

     

    *itab and itab_new are of same type and itab_new should have the count

     

    Regards,

    Ravi Kanth Talagana

    *****************

     

    I would add a couple of details.

     

    itab and itab_new will look like:

     

    f1 f2 f3 f4 count

     

    where count is an integer and should be equal to 1 for each line in itab.

    Also, f1 - f4 are all non-numeric.

    Now when you run Ravi's code above itab_new-count will have the record

    count that you are looking for.

     

    Now you can go ahead and  delete adjacent duplicates.

     

    Regards

    Greg Kern

Actions