Skip to Content

deleting records from internal table

Hi Guys

I would like to delete duplicate records from the table below. I had put a flag in the table, not sure if its useful. I need to delete records marked X but only where the calmonth is repeated. Like in the below records calmonth 201405 & 201408 should not be deleted because they are single entries. But calmonth 201310, 201311 etc. marked X should be deleted. Please let me know the statement. Thanks a lot

12345 201309 EA EA 1 0 30 2,514,927 0 0 12345 201310 EA EA 0 0 30 3,001,875 0 486,948 12345 X 201310 EA EA 2,514,927 0 30 2,514,927 0 0 12345 201311 EA EA 0 0 30 2,901,875 100,000 0 12345 X 201311 EA EA 2,514,927 0 30 3,001,875 0 0 12345 201312 EA EA 0 0 30 3,461,297 0 559,422 12345 X 201312 EA EA 2,514,927 0 30 2,901,875 0 0 12345 201401 EA EA 0 0 30 3,547,771 100,000 186,474 12345 X 201401 EA EA 2,514,927 0 30 3,461,297 0 0 12345 201402 EA EA 0 0 30 4,107,193 0 559,422 12345 X 201402 EA EA 2,514,927 0 30 3,547,771 0 0 12345 201403 EA EA 0 0 30 4,193,667 100,000 186,474 12345 X 201403 EA EA 2,514,927 0 30 4,193,667 0 0 12345 201404 EA EA 0 0 30 4,939,563 0 745,896 12345 X 201404 EA EA 2,514,927 0 30 4,939,563 0 0 12345 X 201405 EA EA 2,514,927 0 30 4,939,563 0 0 12345 201406 EA EA 0 0 30 5,498,985 0 559,422 12345 X 201406 EA EA 2,514,927 0 30 5,498,985 0 0 12345 201407 EA EA 0 0 30 5,871,933 0 372,948 12345 X 201407 EA EA 2,514,927 0 30 5,871,933 0 0 12345 X 201408 EA EA 2,514,927 0 30 5,871,933 0 0
Add a comment
10|10000 characters needed characters exceeded

Related questions

8 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Sep 23, 2013 at 07:03 AM

    Hi Guru,

    The following statement should work :

    DELETE ADJACENT DUPLICATES FROM I_T COMPARING CALMONTH.

    Before doing this sort the records in the order that you have shown in the example and it should work.

    Regards,

    Saurabh Ojha

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Sep 23, 2013 at 07:26 AM

    I am not an ABAPer. But i can give you some idea.

    Your code should process each record by record with LOOP statement. So that it will check whether the 0calmonth is repeated with the same combination of (12345 and calmonth ). If it repeats then those two records should be deleted.

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Sep 23, 2013 at 08:10 AM

    Hi Gurudatt,

    Saurabh's code is fine as far above entries are concerned.

    But it will not work if there are two entries of calmonth with both flag <> ' X.

    try below code.

    itab2[] = itab1[]. "copy itab1 to itab2.

    

    delete itab2 where flag<>'X'. "entries with flag= X in itab2.

    loop at itab2 into wa2.

    read itab1 into wa1 comparing wa1 -calmonth= wa2-calmonth

    wa1-flag <> 'X'. "same calmonth as of itab2 but not flag = X.(duplicate calmonth).

    if sy-subrc = 0. "if found.

    delete itab1 where flag = 'X' AND calmonth = wa2-calmonth.

    endif.

    endloop.

    thus itab1 will have required records.

    Harshawardhan.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Sep 23, 2013 at 08:25 AM

    Hi Gurudutt,

    Simply use the below statements:

    SORT <i_tab> BY calmonth.

    DELETE ADJACENT DUPLICATES FROM <i_tab> COMPARING calmonth.

    Regards,

    Jatin


    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Sep 23, 2013 at 11:26 AM

    SORT ITAB BY FIELD.

    DELETE ADJACENT DUPLICATES FROM ITAB COMPARING FIELD.
    LOOP AT ITAB INTO WA.
    WRITE:/ WA_TABLE NAME-FIELD.
    ENDLOOP.

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Sep 23, 2013 at 12:12 PM

    Hi,

    Same as what others suggested.

    First sort your internal table by calmonth and use the syntax Delete adjacent duplicates internal table comparing calmonth.

    Hope that helps.

    Regards,

    AL

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Sep 23, 2013 at 03:29 PM

    Hi,

    Check out this example.

    REPORT Z_TEST_MP1.

    TYPES : BEGIN OF tb,

    a TYPE string,

    b TYPE c,

    END OF tb,

    tt_tb TYPE TABLE OF tb.

    DATA: p TYPE tt_tb,

    q TYPE tb.

    q-a = '1'.

    q-b = 'X '.

    APPEND q to p.

    q-a = '1'.

    q-b = ' '.

    APPEND q to p.

    q-a = '2'.

    q-b = ' '.

    APPEND q to p.

    q-a = '2'.

    q-b = ' X'.

    APPEND q to p.

    q-a = '3'.

    q-b = 'X'.

    APPEND q to p.

    q-a = '3'.

    q-b = ' '.

    APPEND q to p.

    q-a = '3'.

    q-b = 'X'.

    APPEND q to p.

    SORT p BY a b.

    DELETE ADJACENT DUPLICATES FROM p COMPARING a .

    LOOP AT p INTO q.

    WRITE : / q-a, q-b.

    ENDLOOP.

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Sep 23, 2013 at 06:04 AM

    Hi

    Are you planning on doing full loads all the time? Otherwise your logic won't work for records you have already loaded in an earlier request. You can't delete those anymore.

    You might be better off to design the DSO with the keyfigures on overwrite or you create an exception aggregation LAST on your keyfigures with reference characteristic calday. This way it will always bring the newest record.

    hope it helps

    Martin

    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.