Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

delete operation on internal table

Former Member
0 Likes
2,131

i have a internal table of 20 rows of data. from this internal table i want to delete 5th 7th and 12th row.how it can be done?

i have a internal table of 20 rows of data. from this internal table i want to delete 5th 7th and 12th row.how it can be done?

12 REPLIES 12
Read only

Former Member
0 Likes
1,715

hi

loop into the internal table. Use the system variable

data: counter(2) type c value '0'.

Loop into itab.

counter = counter + 1

if counter = ( 5 or 7 or 12)

Delete itab.

endloop.

Regards

Ramesh

Read only

Former Member
0 Likes
1,715

Hi,

i have a internal table of 20 rows of data. from this internal table i want to delete 5th 7th and 12th row.how it can be done?

Try this

Delete itab index 5.

delete itab index 6.

delete itab index 10.

Hope this will sole your problem.

Regards,

Vijay

Read only

Former Member
0 Likes
1,715

Hello

delete itab index 12.

delete itab index 7.

delete itab index 5.

Read only

Former Member
0 Likes
1,715

Hi

U need to calculate the new position of the record to be deleted after deleting the previous record:

- A) Delete record five

- B) The record 7 will be 6 and 12 will be 11

- C) Delete record 6, 11 will be 10

- D) Delete record 10

So:

DELETE ITAB INDEX 5.
DELETE ITAB INDEX 6.
DELETE ITAB INDEX 10.

Max

Read only

Former Member
0 Likes
1,715

or

can loop in to the internal table. use the system variable, sy index which hold the loop count. check whether the count is 5 or 7 or 12.

If it is so , then delete itab.

else continue.

Read only

Former Member
0 Likes
1,715

It is not a good method to delete itab when it is inside the loop. What you can do is set a flag.

Loop at itab into wa.

< condition>

wa_flag = 'X'.

modify itab from wa transporting flag.

endloop.

delete itab where flag = 'X'.

Read only

Former Member
0 Likes
1,715

REPORT ZTEST.

DATA: BEGIN OF IT_TBL OCCURS 0,

LINE TYPE I,

END OF IT_TBL.

DATA: LV_CNT TYPE I.

DO 20 TIMES.

LV_CNT = LV_CNT + 1.

IT_TBL-LINE = LV_CNT.

APPEND IT_TBL.

ENDDO.

delete it_tbl INDEX 5.

delete it_tbl INDEX 7.

delete it_tbl INDEX 12.

LOOP AT IT_TBL.

WRITE: / IT_TBL-LINE.

ENDLOOP.

Read only

Former Member
0 Likes
1,715

1 way is :

constants : i5 type sy-tabix value 5,
                 i7 type sy-tabix value 7,
                 i15 type sy-tabix value 15.
.......................
...................
DELETE scarr_tab INDEX: i5,i7,i15.

Read only

murat_kaya
Participant
0 Likes
1,715

Hi Souvik,

deleting internal table row using index is not an effective way because after deleting any row, the indexes of the remaining lines change. this may cause problems and you may delete wrong lines. you better use some field combination that qualifies as a key for the line and delete from internal table giving the values to this or these fields. otherwise you can easily delete using "delete itab index n." but after every deletion the index of the next lines to be deleted should be decreased by 1.

regards,

Murat Kaya

Read only

0 Likes
1,715

the better way wud be,,,

loop at *itab1* into is1.
  if sy-tabix <> '5' or sy-tabix <> '7' or sy-tabix <> '15'.
      append  is1 to *itab2*.
  endif.
  clear : is1. 
endloop.

this way u get the table itab2 with all records from itab1 except 5,7,15 th row.

Read only

Former Member
0 Likes
1,715

Hi,

Just a small change.

IF it is 5, 7 , 12, 15,18

Loop into itab.

counter = counter + 1

if counter = ( 5 or 6 or 10, 12,14)

Delete itab.

endif.

endloop.

Also you can try this

Loop at itab into wa.

if not index = (5 or 7 or 12)

move wa to itab1.

append itab1.

endif.

endloop.

Read only

Former Member
0 Likes
1,715

Hi ,

for deleting 5th 7th and 12th row ,

do it in descending order , like


delete itab index 12.
delete itab index 7.
delete itab index 5.

other wise if you delete 5 th record , then the count decreases , 7 th record becomes 6 th record and in this cases wrong record might be deleted .

Regards

Aby