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.
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.
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.
Nice code Srihara. I'll remember that.
Minor edits, clarify explanation.
Message was edited by: