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 internal table rows without using loop statement

Former Member
0 Likes
3,277

i have an internal table which consists of 100 records.

i need to keep only first 5 records.

without using the loop statement i need to delete the rest of the records. how can we achieve this result.

i.e. delete itab1 where "recordno" > 5.

regards.

ZG

1 ACCEPTED SOLUTION
Read only

MarcinPciak
Active Contributor
0 Likes
1,811

Hi,

Use


delete table itab from 6.  "delete all data where index > 5

Regards

Marcin

4 REPLIES 4
Read only

MarcinPciak
Active Contributor
0 Likes
1,812

Hi,

Use


delete table itab from 6.  "delete all data where index > 5

Regards

Marcin

Read only

Former Member
0 Likes
1,811

Hi,

SORT itab BY "field name" DESCENDING.

DELETE itab FROM 6.

Thanks,

Read only

Former Member
0 Likes
1,811

Use as :

delete itab1 from 5.

Read only

Former Member
0 Likes
1,811

Hi,

Delete itab [FROM idx1] [TO idx2] {Where (log_exp)]

To delete several lines at once, you have to specify at least one of the additions FROM, TO, or WHERE. You can only use the additions FROM and TO with standard tables and sorted tables.

Delete itab [FROM idx1]

If you specify FROM, all the table rows from the table index idx1 onwards are included.

Delete itab [TO idx2]

If you specify TO, all the table rows from the table index idx2 onwards are included.

PARAMETERS: p_carrid TYPE sflight-carrid,

p_connid TYPE sflight-connid.

DATA: BEGIN OF seats,

fldate TYPE sflight-fldate,

seatsocc TYPE sflight-seatsocc,

seatsmax TYPE sflight-seatsmax,

seatsfree TYPE sflight-seatsocc,

END OF seats.

DATA seats_tab LIKE STANDARD TABLE OF seats.

SELECT fldate seatsocc seatsmax

FROM sflight

INTO TABLE seats_tab

WHERE carrid = p_carrid AND

connid = p_connid.

LOOP AT seats_tab INTO seats.

seats-seatsfree = seats-seatsmax - seats-seatsocc.

MODIFY seats_tab INDEX sy-tabix FROM seats.

ENDLOOP.

ENDLOOP.

SORT seats_tab BY seatsfree DESCENDING.

DELETE seats_tab FROM 5.

Thanks & Regards,

ShreeMohan

Edited by: ShreeMohan Pugalia on Jul 21, 2009 4:28 PM