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

Hello experts..deleting entries in internal table.

I am having internal table with fields ...mblnr werks bwart matnr menge etc. The records are like this

mblnr werks bwart matnr menge etc

1) 2222200123 an20 10 12111111111 20 .....

2) 2222200123 an20 98 12111111119 20 .....

3) 2222200123 an20 99 12111111113 20 .....

4) 2222200124 an20 10 12111111112 20 .....

5) 2222200125 an20 25 12111111115 20 .....

6) 2222200125 an20 98 12111111117 20 .....

7) 2222200125 an20 97 12111111121 20 .....

I want to have the records that have same document number.ie in above i want 1, 2,3, 5,and 6, 7 but not 4 because that is only single document. ie I wanted the repeated document number records .so please tell me what to do .Thank you very much.

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

4 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Oct 08, 2007 at 11:03 PM

    Shiva,

    Srihari's code looks very good, although it could be optimized a little.

    The others have problems.

    Sudhir's code doesn't compare the correct field (it uses matnr, when it should use mblnr).

    In addition, the form of the DELETE that he uses is incorrect.

    He uses

    DELETE FROM itab USING lv_index.

    which should be

    DELETE itab INDEX lv_index.

    Even if these were corrected, it is extremely inefficient, with a loop inside a loop.

    -


    John's code is inefficient since the DELETE will cause a sequential access each time, since he is not deleting using the index.

    In addition, I am uncertain about the procedure he is using in moving itab to itab_temp. If itab_temp has unique keys, it will cause a short dump.

    If it doesn't, there will be no short dump, but I do not know what is to be gained by it.

    It looks like you wouldn't delete what you expect with his code.

    The read should get a hit everytime, so what will be deleted?

    -


    Srihara's code could be optimized as follows, though the changes I suggest are trivial. Srihara deserves your thanks most of all:

    FIELD-SYMBOLS: <wa_mat> type any.
    DATA: count type i.
     
    SORT it_tab BY mblnr.
     
    LOOP AT it_tab ASSIGNING <wa_mat>.
      count = count + 1.
     
      AT END OF mblnr.
        IF count = 1.
          CLEAR <wa_mat>-mblnr.
        ENDIF.
        CLEAR count.
      ENDAT.
     
    ENDLOOP.
     
    DELETE it_tab WHERE mblnr IS INITIAL.

    -


    Good luck

    Nice code Srihara. I'll remember that.

    Brian

    Minor edits, clarify explanation.

    Message was edited by:

    Brian Sammond

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Oct 08, 2007 at 06:22 PM

    User SORT on the internal table with the Document Number.

    itab_tmp[] = itab[].

    LOOP AT itab.

    lv_index = sy-tabix.

    CLEAR count.

    LOOP AT itab_tmp WHERE matnr = itab_tmp-matnr.

    count = count + 1.

    ENDLOOP.

    IF count EQ 1.

    DELETE FROM itab USING lv_index.

    ENDIF.

    ENDLOOP.

    Message was edited by:

    Sudhir K Atluru

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Oct 08, 2007 at 07:25 PM

    Hello,

    Try this:

    itab type table of <your_type>,

    itab_temp type sorted table of <your_type>.

    data: wtab like line of itab.

    Itab_temp[] = itab[].

    Loop at itab into wtab.

    read table itab_temp with key [document] = wtab-[document]

    transporting no fields.

    if sy-subrc <> 0.

    delete table itab from wtab.

    endif.

    Endloop.

    Hope it helps,

    Regards,

    John.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Oct 08, 2007 at 07:26 PM

    This is how I would do it :

    FIELD-SYMBOLS: <wa_mat> type any.
    DATA: count type i,
          blank type mblnr.
    
    SORT it_tab BY mblnr.
    
    LOOP AT it_tab ASSIGNING <wa_mat>.
    count = count + 1.
    
    AT END OF mblnr.
    if count = 1.
    clear <wa_mat>.
    endif.
    clear count.
    ENDAT.
    
    ENDLOOP.
    
    DELETE it_tab WHERE mblnr = blank.
    

    Message was edited by:

    Srihari Hebbar

    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.