2009 May 29 10:05 AM
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?
2009 May 29 10:09 AM
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
2009 May 29 10:10 AM
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
2009 May 29 10:11 AM
Hello
delete itab index 12.
delete itab index 7.
delete itab index 5.
2009 May 29 10:13 AM
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
2009 May 29 10:13 AM
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.
2009 May 29 10:13 AM
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'.
2009 May 29 10:16 AM
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.
2009 May 29 10:17 AM
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.
2009 May 29 10:20 AM
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
2009 May 29 10:25 AM
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.
2009 May 29 10:35 AM
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.
2009 May 29 10:49 AM
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
| User | Count |
|---|---|
| 3 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |