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

How to delete rows from internal table

Karan_Chopra_
Active Participant
77,802

i have a internal table fetching some entries from a data base table plz tell me after fetchin details from database table into internal table how can i delete some entries from internal table

8 REPLIES 8
Read only

Former Member
0 Likes
20,621

Hi Karan ,

Use the command DELETE.

The syntax will be DELETE <ITAB> WHERE <CONDITION>.

Please see the help for DELETE command for more info.

Regards

Arun

Read only

gopi_narendra
Active Contributor
0 Likes
20,621

you can just use the delete statement

delete it_tab where <condition>

Regards

Gopi

Read only

Former Member
0 Likes
20,621

depending on the conditions we can delete them

delete itab where field1 eq 'XXX'.

Read only

former_member196280
Active Contributor
0 Likes
20,621

DELETE <internal table Name> WHERE <condition>

Regards,

SaiRam

Read only

Former Member
0 Likes
20,621

hi

<b>delete <field> from itab where <condition>.

modify itab.</b>

regards

ravish

<b>plz dont forget to reward points if helpful</b>

Read only

Former Member
0 Likes
20,621

Hi,

DELETE { {FROM target [WHERE sql_cond]}

| {target FROM source} }.

Effect

The statement DELETE deletes one or more rows from the database table specified in target. The rows that are to be deleted are specified either in a WHERE condition sql_cond or with data objects in source.

System Fields

The statement DELETE sets the values of the system fields sy-subrc and sy-dbcnt.

sy-subrc Meaning

0 A least one row was deleted.

4 At least one row could not be deleted, since it was not found in the database table.

The statement MODIFY sets sy-dbcnt to the number of deleted rows.

DELETE dbtab - cond

Syntax

... WHERE sql_cond.

Effect

The WHERE addition uses a logical expression sql_cond to specify which rows in the database table are deleted. The same applies to the logical expression sql_cond as for the WHERE condition of the SELECT statement. If there is no row in the database that satisfies the WHERE condition, no row is deleted and sy-subrc is set to 4. If no WHERE condition is specified, all rows are deleted.

Note

As of Release 6.10, specifying the WHERE condition is optional. Prior to Release 6.10, you had to specify the WHERE condition in this variant of the DELETE statement and you could not use dynamic logical expressions.

Example

In the following example, all an airline's flights for today in which no seats are occupied are deleted from the database table SFLIGHT (see also, example to dtab-source).

PARAMETERS p_carrid TYPE sflight-carrid.

DELETE FROM sflight

WHERE carrid = p_carrid AND

fldate = sy-datum AND

seatsocc = 0.

Syntax

... FROM wa|{TABLE itab}.

Alternatives:

1. ... FROM wa

2. ... FROM TABLE itab

Effect

After FROM, you can specifiy a data object wa that is not table-type or an internal table itab. The content of the data objects determines the row(s) to be deleted.

Alternative 1

... FROM wa

Effect

If you specify a work area wa that is not table-type, a row is searched for in the database table whose primary key content is the same as that of the corresponding initial part of the work area. The content of the work area is not converted and is interpreted according to the structure of the database table or view. This row is deleted. The work area must meet the prerequisites for use in Open SQL statements.

If there is no row in the database with the same content as the primary key, no row is deleted and sy-subrc is set to 4.

Notes

The work area wa should be declared wit reference to the database table or view in the ABAP Dictionary using the length of the primary key.

If the database table of view are specified statically, you do not have to specify the work area with FROM wa outside of classes if a table work area dbtab is declared for the relevant database table or view using the TABLES statement. The system then implicitly adds the FROM dbtab addition to the DELETE statement.

Alternative 2

... FROM TABLE itab

Effect

If an internal table itab is specified, the system processed all rows of the internal table according to the rules for the work area wa. The row type of the internal table must meet the prerequisites for use in Open SQLstatements.

If, for a row of the internal table, there is no row in the database with the same content as the primary key, the corresponding row is ignored and sy-subrc is set to 4. If the internal table is empty, sy-subrc is set to 0. The system field sy-dbcnt is always set to the number of rows actually deleted.

Example

In the following example, all today's flights of an airline in which no seats are occupied are deleted from the database table SFLIGHT. The client field must be in the row structure of the internal table sflight_key_tab. Otherwise it does not cover the primary key of the database table and incorrect key values will be accepted as a result. This example has the same function as that for dtab-cond, but it requires two database accesses. The deleted rows are recorded in the internal table.

PARAMETERS p_carrid TYPE sflight-carrid.

TYPES: BEGIN OF sflight_key,

mandt TYPE sflight-mandt,

carrid TYPE sflight-carrid,

connid TYPE sflight-connid,

fldate TYPE sflight-fldate,

END OF sflight_key.

DATA sflight_key_tab TYPE TABLE OF sflight_key.

SELECT carrid connid fldate

FROM sflight

INTO CORRESPONDING FIELDS OF TABLE sflight_key_tab

WHERE carrid = p_carrid AND

fldate = sy-datum AND

seatsocc = 0.

DELETE sflight FROM TABLE sflight_key_tab.

Regards,

Priyanka.

Read only

S0025444845
Active Participant
0 Likes
20,621

Hi,

You can delete by using

Delete itab where <condition>

and if u want to delete dublicate entries than use

soer itab by <key>.

delete adjacent duplicates from itab by comaparing <key>

regards,

sudha.

reward points if useful.

Read only

Former Member
0 Likes
20,621

Hi

Use DELETE command with appropriate Key fields.

For Eg: Delete adjascent Duplicates from itab comparing <fild1 fild2.....fieldn>

Reward All Helpfull Answers...........