‎2007 Aug 27 5:29 AM
Hi all,
For eg my internal table has 1000 records.I want only the 1st 300 records .Rest of the record i want to delete .How to do this.
Thanks in advance,
Alex.
‎2007 Aug 27 5:32 AM
Alex,
loop at itab.
if sy-tabix GE 300.
delete itab.
endif.
endloop.
But deleting the itab depending on the sy-tabix is not logically right,I think.Generally we do w.r.t a field.
K.Kiran.
‎2007 Aug 27 5:32 AM
Alex,
loop at itab.
if sy-tabix GE 300.
delete itab.
endif.
endloop.
But deleting the itab depending on the sy-tabix is not logically right,I think.Generally we do w.r.t a field.
K.Kiran.
‎2007 Aug 27 5:34 AM
Hii..
The better way is:
Declare a Seperate Itab:
Eg:
DATA: IT_TEMP TYPE TABLE OF <SAME STRUCTURE>.
APPEND LINES OF ITAB FROM 1 TO 300 TO IT_TEMP.
REFRESH ITAB.
**Now the First 300 records will be present in the table IT_TEMP.
<b>reward if Helpful</b>
‎2007 Aug 27 5:38 AM
Instead of using loop endloop, we can try something like this to improve performan e.
Describe itab lines size. " get the total lines of table
if size GE 300 .
append lines of itab to itab_tmp from 1 to 300.
refresh itab.
itab[] = itab_tmp[].
else.
do nothing.
endif.
Code mentioned may not be correct syntectically but try this logic for better performance.
Regards
Sushil
‎2007 Aug 27 5:38 AM
‎2007 Aug 27 5:38 AM
HI,
Sort the internal table for your first 300 records.
then
delete <ITAB> from 301 to 1000.
rewards if uesful,
regards,
'Nazeer'
‎2007 Aug 27 5:48 AM
Hi Nazeer,
What u r saying is exactly correct.
This is my small logic.
loop at itab.
if sy-tabix <= 300.
append itab to new_itab.
else.
free itab.
exit.
endif.
endloop.
Regards,
Surya
‎2007 Aug 27 5:39 AM
Hello Alex
Assuming that you fill your itab using a SELECT statement you could restrict the number of records already here, e.g.:
SELECT * FROM knb1 INTO TABLE gt_myitab UP TO gd_maxno ROWS
WHERE bukrs = '1000'.Alternatively you could either process only the required number of records or delete the obsolete ones:
DATA:
gt_myitab_x TYPE ... .
LOOP AT gt_myitab INTO ls_record FROM 1 TO gd_maxno.
" ...do processing
" collect required records
APPEND ls_record TO gt_myitab_x.
ENDLOOP.
gt_myitab = gt_myitab_x. " contains only gd_maxno records
Regards
Uwe
‎2007 Aug 27 5:40 AM
Hi,
Before Deleting the make sure that you need to sort the internal table.
Loop at Itab.
If sy-index >=300.
Delete itab.
endif.
Endloop.
Thanks
Yogesh