Application Development 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: 

Delete from database Table

Former Member
0 Kudos

Hi,

To delete data from database table using internal table I am using following statement.

DELETE dbtab FROM TABLE itab.

Itab is a sorted table.Just wondering if table type matters while deleting database entries using internal table.which is efficient table type for deleting records from database table?

Regards

Nilesh

3 REPLIES 3

ssimsekler
Active Contributor
0 Kudos

Hi Nilesh

The row type of the internal table must be a data object with at least the same length and alignment as the key structure of the database table. The key is read according to the structure of the table line, and not that of the row type. It is a good idea to define the row type with reference to the structure of the database table.

From SAP Help

DATA: BEGIN OF WA,
CARRID TYPE SPFLI-CARRID,
CONNID TYPE SPFLI-CONNID,
END OF WA,
ITAB LIKE HASHED TABLE OF WA
WITH UNIQUE KEY CARRID CONNID.

WA-CARRID = 'UA'. WA-CONNID = '0011'.
INSERT WA INTO TABLE ITAB.

WA-CARRID = 'LH'. WA-CONNID = '1245'.
INSERT WA INTO TABLE ITAB.

WA-CARRID = 'AA'. WA-CONNID = '4574'.
INSERT WA INTO TABLE ITAB.

...

DELETE SPFLI FROM TABLE ITAB.

Besides, it is so technical what algorithm is run to delete records from the DB table when an internal table is given. If you want you can have a quick test using GET TIME. However, it seems logical that if your internal table is sorted with respect to any index, especially the primary index, of the DB table this may increase performance.

Regards

*--Serdar <a href="https://www.sdn.sap.com:443http://www.sdn.sap.comhttp://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.sdn.businesscard.sdnbusinesscard?u=qbk%2bsag%2bjiw%3d">[ BC ]</a>

0 Kudos

Thanks

Nilesh

Former Member
0 Kudos

Hi,

While using delete dbtab check whether you are using the same table type for the internal table you have specified. If not while executing it will give a dump.

So first move the internal table into a table of type dbtab and then use delete.

<i>Mass deletion: Deletes all database table lines for which the internal table itab contains values for the primary key fields. The lines of the internal table itab must satisfy the same condition as the work area wa in addition 1 to variant 2.

The system field SY-DBCNT contains the number of deleted lines, i.e. the number of lines of the internal table itab for whose key values there were lines in the database table dbtab.

The return code is set as follows:

SY-SUBRC = 0:

All lines from itab could be used to delete lines from dbtab.

SY-SUBRC = 4:

For at least one line of the internal table in the database table, there was no line with the same primary key. All found lines are deleted.

Note

If the internal table itab is empty, SY-SUBRC and SY-DBCNT are set to 0.</i>

Thanks & Regards,

Judith.