Former Member

# deleting ITAB

Hello friends,

I have an Internal table and it is getting some duplicate values. For example,

I have the same values in line 3, 6 and 9 of the internal table ( All fields have the same value)

I want to delete Line 6 and 9 from the internal table. However i dont want to sort the Internal table.

Any suggestions,

##### Add a comment
10|10000 characters needed characters exceeded

### Related questions

Former Member
Posted on Feb 28, 2007 at 10:49 PM

Hi,

Check this..

DATA: BEGIN OF ITAB OCCURS 0,

VALUE,

END OF ITAB.

DATA: V_INT TYPE SYTABIX.

ITAB-VALUE = '1'. APPEND ITAB.

ITAB-VALUE = '2'. APPEND ITAB.

ITAB-VALUE = '3'. APPEND ITAB.

ITAB-VALUE = '1'. APPEND ITAB.

ITAB-VALUE = '4'. APPEND ITAB.

ITAB-VALUE = '3'. APPEND ITAB.

LOOP AT ITAB.

CLEAR: V_INT.

LOOP AT ITAB WHERE VALUE = ITAB-VALUE.

V_INT = V_INT + 1.

IF V_INT > 1.

DELETE ITAB.

ENDIF.

ENDLOOP.

ENDLOOP.

Thanks,

Naren

##### Add a comment
10|10000 characters needed characters exceeded
• Former Member
Posted on Feb 28, 2007 at 10:41 PM

Use DELETE itab INDEX idx.

Thanks,

Santosh

##### Add a comment
10|10000 characters needed characters exceeded
• Former Member Former Member

Thanks All,

I will try the logic suggested.

However the order is very important here. Its basically the IDOC segments, So I cant sort. One more important thing is when I am deleting the ITAB i cant delete the first hit record. As i said in my post from line 3, 6 and 9 i cant delete 3.

THanks,

• Posted on Feb 28, 2007 at 10:49 PM

Hi,

Eg. Itab has your internal table

itab1[] = itab[].

sort itab1 by <your field name >

delete adjacent duplicates from itab1 comparing <your field name>

loop at itab1.

read table itab with key <field Name > = itab1-<fieldname>

if sy-subrc eq 0

delete itab index sy-tabix.

endif.

endloop.

After this loop itab contain the records as you mentioned.

ie Every first entry in itab of the key has been deleted.

aRs

##### Add a comment
10|10000 characters needed characters exceeded
• Former Member
Posted on Feb 28, 2007 at 11:04 PM

hi

You can delete the multiple records from database table by putting all the records which u want to delete in internal table.

DELETE SMARA FROM TABLE ITAB.

in this case whatever you have in internal table will be deleted from SMARA.

append the internal table.

else try this :

SORT itab ASCENDING BY xxx.

DELETE ADJACENT DUPLICATES FROM itab COMPARING xx.

else : You can solve your prob using below code:

DATA: ind(1), p_val like itab-field1.

SORT itab ASCENDING field1.

LOOP AT itab INTO wa_itab.

CLEAR: p_val, ind.

ON CHANGE OF field1.

p_val = itab-field1.

ind = 'X'.

ENDON.

IF itab-field1 = p_val AND NOT ind IS INITIAL.

DELETE itab INDEX sy-tabix.

ENDIF.

ENDLOOP.

sri

award points if helpful

##### Add a comment
10|10000 characters needed characters exceeded
• Former Member
Posted on Feb 28, 2007 at 11:11 PM

Hi,

Thanks,

Naren

##### Add a comment
10|10000 characters needed characters exceeded
• Posted on Feb 28, 2007 at 10:39 PM

Hi,

You can use index number to delete rows.

DELETE itab INDEX sy-tabix.

Regards,

Amit

##### Add a comment
10|10000 characters needed characters exceeded