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

Deleting Adjacent Duplicate Entries

hi friends can any one explain about Deleting Adjacent Duplicate Entries with an example porgram.

points will be given

thanks

vijaya

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

8 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Jan 18, 2008 at 10:28 AM

    Delete adjacent duplicate entries will delete duplicate rows in a internal table based on key fields specified.

    F1 F2 F3

    -


    AA ZX 78

    AA ZX 99

    BA RE 99

    CS ZX 78

    CS TX 56

    CS TX 46

    Consider a internal table with above structure.

    If I write

    Delete adjacent duplicates from itab comparing F1 F2.

    Result:

    -


    AA ZX 78

    BA RE 99

    CS ZX 78

    CS TX 56

    Delete adjacent duplicates from itab comparing F2.

    F1 F2 F3

    -


    AA ZX 78

    BA RE 99

    CS TX 56

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Jan 18, 2008 at 10:28 AM

    hi

    vijaya

    REPORT zintoperations.

    TYPES:BEGIN OF itab,

    num TYPE i,

    name(10) TYPE c,

    amt TYPE i,

    END OF itab.

    DATA : wa_itab TYPE itab,

    it_itab TYPE STANDARD TABLE OF itab.

    DATA : v_lines TYPE i.

    wa_itab-num = 1.

    wa_itab-name = 'nag'.

    wa_itab-amt = 1000.

    APPEND wa_itab TO it_itab.

    wa_itab-num = 1.

    wa_itab-name = 'nag'.

    wa_itab-amt = 2000.

    APPEND wa_itab TO it_itab.

    wa_itab-num = 1.

    wa_itab-name = 'nag'.

    wa_itab-amt = 1500.

    APPEND wa_itab TO it_itab.

    wa_itab-num = 2.

    wa_itab-name = 'sri'.

    wa_itab-amt = 500.

    APPEND wa_itab TO it_itab.

    wa_itab-num = 2.

    wa_itab-name = 'sri'.

    wa_itab-amt = 600.

    APPEND wa_itab TO it_itab.

    wa_itab-num = 2.

    wa_itab-name = 'sri'.

    wa_itab-amt = 700.

    APPEND wa_itab TO it_itab.

    wa_itab-num = 3.

    wa_itab-name = 'ganesh'.

    wa_itab-amt = 1200.

    APPEND wa_itab TO it_itab.

    wa_itab-num = 3.

    wa_itab-name = 'ganesh'.

    wa_itab-amt = 1300.

    APPEND wa_itab TO it_itab.

    wa_itab-num = 3.

    wa_itab-name = 'ganesh'.

    wa_itab-amt = 1400.

    APPEND wa_itab TO it_itab.

    wa_itab-num = 4.

    wa_itab-name = 'suresh'.

    wa_itab-amt = 900.

    APPEND wa_itab TO it_itab.

    wa_itab-num = 4.

    wa_itab-name = 'suresh'.

    wa_itab-amt = 300.

    APPEND wa_itab TO it_itab.

    *

    *

    *

    LOOP AT it_itab INTO wa_itab.

    WRITE:/ sy-tabix, wa_itab-num , wa_itab-name , wa_itab-amt.

    ENDLOOP.

    DELETE ADJACENT DUPLICATES FROM it_itab COMPARING num.

    LOOP AT it_itab INTO wa_itab.

    modify it_itab from wa_itab.

    WRITE:/ sy-tabix, wa_itab-num , wa_itab-name , wa_itab-amt.

    ENDLOOP.

    Regards

    Nagesh.Paruchuri

    Add a comment
    10|10000 characters needed characters exceeded

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

    sort your internal table by those fields based on which you want to delete.

    for ex you have f1 and f2 in itab.

    sort itab by f1 f2.

    DELETE ADJACENT DUPLICATES FROM itab compairing f1 f2.

    pankaj

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 18, 2008 at 10:30 AM

    Hi

    syntax is

    sort itab by field1 field2..........

    DELETE ADJACENT DUPLICATES FROM ITAB.

    It compares values of all the fields of different columns of ITAB

    sort itab by field1 field2..........

    DELETE ADJACENT DUPLICATES FROM ITAB

    compairing feild1 feild2.

    It compares values of only the field1 and field2 of different columns of ITAB

    Always sort ITAB before using delete statement otherwise there is no benifit because it deletes only adjacent duplicate entries.

    Aditya

    Add a comment
    10|10000 characters needed characters exceeded

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

    Hi,

    Use

    With these additions, the statement DELETE deletes all lines in certain groups of lines, except for the first line of the group. These are groups of lines that follow one another and have the same content in certain components. If the addition COMPARING is not specified, the groups are determined by the content of the key fields.

    Lines are considered to be doubled if the content of neighboring lines is the same in the components examined. In the case of several double lines following one another, all the lines - except for the first - are deleted.

    Addition

    ... COMPARING {comp1 comp2 ...}|{ALL FIELDS}

    Effect

    If the addition COMPARING is specified, the groups are determined either by the content of the specified components comp1 comp2 ... or the content of all components ALL FIELDS. The specification of individual components comp is made as described in the section Specification of Components. Access to class attributes is possible through the object component selector only as of Release 6.10.

    Example

    Deleting all multiple-occurring lines in the internal table connection_tab. The result of this exanple corresponds to the one in the example for the position specification for INSERT.

    DATA: BEGIN OF connection,

    cityfrom TYPE spfli-cityfrom,

    cityto TYPE spfli-cityto,

    distid TYPE spfli-distid,

    distance TYPE spfli-distance,

    END OF connection.

    DATA connection_tab LIKE SORTED TABLE OF connection

    WITH NON-UNIQUE KEY cityfrom cityto

    distid distance.

    SELECT cityfrom cityto distid distance

    FROM spfli

    INTO TABLE connection_tab.

    DELETE ADJACENT DUPLICATES FROM connection_tab.

    Regards,

    Renjith Michael.

    Add a comment
    10|10000 characters needed characters exceeded

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

    Hi,

    DATA OFF TYPE I.

    DATA: BEGIN OF LINE,

    COL1 TYPE I,

    COL2 TYPE C,

    END OF LINE.

    DATA ITAB LIKE STANDARD TABLE OF LINE

    WITH NON-UNIQUE KEY COL2.

    LINE-COL1 = 1. LINE-COL2 = 'A'. APPEND LINE TO ITAB.

    LINE-COL1 = 1. LINE-COL2 = 'A'. APPEND LINE TO ITAB.

    LINE-COL1 = 1. LINE-COL2 = 'B'. APPEND LINE TO ITAB.

    LINE-COL1 = 2. LINE-COL2 = 'B'. APPEND LINE TO ITAB.

    LINE-COL1 = 3. LINE-COL2 = 'B'. APPEND LINE TO ITAB.

    LINE-COL1 = 4. LINE-COL2 = 'B'. APPEND LINE TO ITAB.

    LINE-COL1 = 5. LINE-COL2 = 'A'. APPEND LINE TO ITAB.

    OFF = 0. PERFORM LIST.

    DELETE ADJACENT DUPLICATES FROM ITAB COMPARING ALL FIELDS.

    OFF = 14. PERFORM LIST.

    DELETE ADJACENT DUPLICATES FROM ITAB COMPARING COL1.

    OFF = 28. PERFORM LIST.

    DELETE ADJACENT DUPLICATES FROM ITAB.

    OFF = 42. PERFORM LIST.

    FORM LIST.

    SKIP TO LINE 3.

    LOOP AT ITAB INTO LINE.

    WRITE: AT /OFF LINE-COL1, LINE-COL2.

    ENDLOOP.

    ENDFORM.

    Plzz reward points if it helps.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 18, 2008 at 10:40 AM

    Hi,

    Below is the scenario,

    Itab

    F1 F2

    A 100

    B 200

    A 50

    Now In the above itab we have two entries with A and one entry with B, Now would like have only one entry of A and B.

    Sort itab by F1.

    Delete adjacent duplicates from itab comparing F1.

    Due to the above statement itab will have A 100 and B 200 as table entries of itab.

    In Addition to this if you use as below :

    delete adjacent duplicates from itab comparing itab with all field.

    Now you will have all 3 entries, because the value in F2 for second A is 50.

    Hope this is helpful.

    Thanks,

    Sriram Ponna.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 18, 2008 at 10:55 AM

    Hi Vijaya,

    DELETE ADJACENT DUPLICATES FROM itab.

    Extras:

    ... COMPARING f1 f2 ...

    ... COMPARING ALL FIELDS

    Effect

    Deletes adjacent duplicate entries from the internal table itab. If there are n duplicate entries in succession, the first entry is retained, and the following n-1 entries are deleted.

    Two lines are regarded as duplicates if their keys are identical.

    The Return code is set as follows:

    SY-SUBRC = 0:

    At least one duplicate was found, and at least one entry was deleted.

    SY-SUBRC = 4:

    No duplicates found, no entries deleted.

    Addition 1

    ... COMPARING f1 f2 ...

    Effect

    Two lines of the internal table itab are regarded as duplicates if they have identical contents in the fields f1, f2, ...

    Addition 2

    ... COMPARING ALL FIELDS

    Effect

    Two lines of the internal table are regarded as duplicates if all of their field contents are identical.

    Notes

    1. The DELETE ADJACENT DUPLICATES statement works particularly well if you have sorted the internal table itab according to the fields that you want to compare when looking for duplicates. In this case, deleting adjacent duplicates is the same as deleting all duplicates. The direction of the sort is irrelevant.

    2. If you do not know a comparison expression until runtime, you can specify it dynamically as the contents of the field name in the expression COMPARING ... (name) .... If name is empty at runtime, the comparison expression is ignored. If name contains an invalid component name, a runtime error occurs.

    3. You can further restrict comparison expressions - both static and dynamic - by specifying offset and length.

    see the link below for example

    http://help.sap.com/saphelp_nw04/helpdata/en/06/aafd54fc4011d195280000e8353423/content.htm

    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.