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

Deleting record from internal table

Former Member
0 Likes
1,463

Hiii

In a looop i want to delete a record from internal table.

Can some1 plxzz tell me how can i do it?

Will delete itab will delete that record in loop?

waitin very eagerly 4 replies

Hiii

In a looop i want to delete a record from internal table.

Can some1 plxzz tell me how can i do it?

Will delete itab will delete that record in loop?

waitin very eagerly 4 replies

12 REPLIES 12
Read only

Former Member
0 Likes
1,430

Hi,

you will only delete the currently record from the itab with "delete itab".

If you use it in combination with

loop at itab.

delete itab.

endloop.

it will work.

Otherwise you can work with . DELETE itab FROM idx1 TO idx2.

Regards

Nicole

Read only

0 Likes
1,430

Hi,

Yes Delete itab inside a loop will delete the record one by one as the delete index is set as the loop index.

Thats is in the first pass of the loop the index is 1 and if you use a delete statement then the system will delete the first record and so on.

Within a loop you dont have to specify a index explicitly.

Cheers

VJ

Read only

Former Member
0 Likes
1,430

You can delete the multiple records from database table by putting all the records, which you want to delete in internal table. For example

DELETE SFLIGHT FROM TABLE ITAB.

In this case whatever you have in internal table will be deleted from SFLIHT.

Note: append internal table with all the entries, which you want to delete.

Read only

rahulkavuri
Active Contributor
0 Likes
1,430

If u are in a loop then u need to use

delete itab index sy-tabix.

Read only

Former Member
0 Likes
1,430

Hello,

Just do this in order to delete the current record from itab.

loop at itab.
delete itab.
endloop

If useful reward,

Vasanth

Read only

Former Member
0 Likes
1,430

Hi Rajiv,

Try this:

Loop at itab.
if <somecondition>. "ur condition...
delete itab.
endif.
endloop.

Hope this will help u.

Jogdand M B

Read only

Former Member
0 Likes
1,430

Hi Rajiv,

U can use the statement as given below:

delete it_tab where fld = tab-fld

or

delete it_tab1 at i_index_p.

In case u want to delete all records from your table then use:

clear: itab, itab[]. Refresh itab.

DELETE - itab_lines

Syntax

... itab [FROM idx1] [TO idx2] [WHERE log_exp]... .

Extras:

1. ... FROM idx1

2. ... TO idx2

3. ... WHERE log_exp

Effect

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.

If you specify several of the additions, the rows are deleted that result from the intersection of the individual additions.

Addition 1

... FROM idx1

Effect

If you specify FROM, all the table rows from the table index idx1 onwards are included. idx1 must be a data object with type i. If the value of idx1 is less than or equal to 0, a runtime error occurs. If the value is greater than the number of table rows, no rows are deleted.

Addition 2

... TO idx2

Effect

If you specify TO, only the table rows up to table index idx2 are included. idx2 must be a data object with type i. If the values of idx2 is less than or equal to 0, a runtime error occurs. If the value is greater than the number of table rows, it is set to the number of rows. If idx2 is less than idx1, no rows are deleted.

Addition 3

... WHERE log_exp

Effect

You can specify any logical expression log_exp after WHERE, for which the first operand of each individual comparison is a component of the internal table. This enables all logical expression with the exception of IS ASSIGNED, ISREQUESTED, and IS SUPPLIED. The dynamic specification of components using character-type data objects in parentheses is not supported here. All rows for which the logical expression is true are deleted.

Note

Whereas every row of the internal table is checked for the logical expression of the WHERE addition in standard tables and hashed tables, you can use linked AND queries to optimize the access to sorted tables by checking at least the starting component of the table key for equality with the logical expression.

Example

Deletes all rows of an internal table from row 4. The result is the same as in the example for APPEND ... SORTED BY.

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 4.

If Helpful reward with some points.

Regards,

Pulokesh

Message was edited by:

Pulokesh Karmakar

Read only

Former Member
0 Likes
1,430

Hi Rajiv,

The below code you can use to delete a single based on some where condition;

Loop at i_lips2 INTO w_lips2.

delete itab where matnr ne w_lips2-matnr.

Endloop.

Read only

Former Member
0 Likes
1,430

Hi Rajiv,

loop at itab.

if i_tab-matnr = '0000000000000001'.

delete itab.

endif.

endloop.

or

DELETE ITAB INDEX 450

Reward points if helpful.

Regards,

Hemant

Read only

Former Member
0 Likes
1,430

Hi Rajiv,

If you want a single record you can use following Code:

Loop at i_lips into wa_lips.

delete itab where matnr ne wa_lips-matnr.

Endloop.

Regards,

Daniel

Read only

Former Member
0 Likes
1,430

Deleting a record from an internal table will take the following forms:

Delete from an internal table

- DELETE itab.

- DELETE itab INDEX idx.

- DELETE itab FROM idx1 TO idx2.

- DELETE itab WHERE cond.

- DELETE ADJACENT DUPLICATES FROM itab.

Regards,

Balakrishna.N

Read only

0 Likes
1,430

hi to delete individual records..

just do this..

1) loop at itab.

delete itab.

endloop.

2) delete itab where..<condition>

3) delete itab index..