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

RE:delete statment

Former Member
0 Likes
932

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.

1 ACCEPTED SOLUTION
Read only

kiran_k8
Active Contributor
0 Likes
912

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.

8 REPLIES 8
Read only

kiran_k8
Active Contributor
0 Likes
913

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.

Read only

varma_narayana
Active Contributor
0 Likes
912

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>

Read only

Former Member
0 Likes
912

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

Read only

Former Member
0 Likes
912

try this

delete itab from 1 to 300.

Read only

Former Member
0 Likes
912

HI,

Sort the internal table for your first 300 records.

then

delete <ITAB> from 301 to 1000.

rewards if uesful,

regards,

'Nazeer'

Read only

0 Likes
912

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

Read only

uwe_schieferstein
Active Contributor
0 Likes
912

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

Read only

Former Member
0 Likes
912

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