SAP DELETE DBTAB ABAP Statements



Get Example source ABAP code based on a different SAP table
  


ID DELETE-DBTAB
• FROM DELETE dbtab
• DELETE dbtab ABAP_STATEMENT_OSQL

DELETE dbtab
Short Reference

ABAP_SYNTAX
DELETE ${ FROM target $[ connection$] $[WHERE sql_cond$] $[db_hints$]
$[ORDER BY ... $[OFFSET o$]$] $[UP TO n ROWS$] $}
$| ${ target $[ connection$] FROM source $}
$[MAPPING FROM ENTITY $].

ABAP_VARIANTS:
1 DELETE FROM target ...
2 DELETE target FROM source.

ABAP Addition
... MAPPING FROM ENTITY

What does it do?
The AB-SQL statement DELETE deletes one or more rows from the DDIC database table
BEGIN_SECTION VERSION 5 OUT or DDIC table view
END_SECTION VERSION 5 OUT specified in target. The rows to be deleted can be specified as follows:
In a variant DELETE FROM target using conditions
In a variant DELETE target FROM using data objects in source
BEGIN_SECTION VERSION 5 OUT
The addition connection can be used to specify a secondary connection .
END_SECTION VERSION 5 OUT
System Fields
The statement DELETE sets the values of the system fields sy-subrc and sy-dbcnt. sy-subrcMeaning 0In the variant DELETE FROM target, at least one row was deleted if a WHERE condition was specified and all or n rows were deleted if no condition was specified. In the variant DELETE target FROM, the specified row was deleted if a work area was specified in source and all specified rows were deleted if an internal table was specified in source or the internal table is empty. 4In the variant DELETE FROM target, no row was deleted if a WHERE condition was specified or no row was deleted if no condition was specified, since the database table was already empty. In the variant DELETE target FROM, no row was deleted if a work area was specified in source or not all specified rows were deleted if an internal table was specified in source.
The statement DELETE sets sy-dbcnt to the number of deleted rows. If an overflow occurs because the number of rows is greater than 2,147,483,647, sy-dbcnt is set to -1.
BEGIN_SECTION SAP_INTERNAL_HINT
On IBM DB2, due to a fast mass deletion, sy-dbcnt does not contain the number of deleted lines if no WHERE condition is used with DELETE on the database (that means also no implicit WHERE condition for the client). Instead, sy-dbcnt contains 1. This behavior can be changed to the slower AB_SQL behavior by profile parameter dbs/db2/use_mass_delete = 0 or by a DB2 specific database hint.
END_SECTION SAP_INTERNAL_HINT



Latest notes:

The rows are deleted permanently from the DDIC database table in the next database commit. Until that point, they can still be undone using a database rollback. The current isolation level defines whether the deleted data can no longer be read into other database LUWs before or only after the database commit.
The number of rows that can be deleted from the tables of a database within a database LUW is limited, since a database system can only manage a limited amount of locks and data in the rollback area.
The statement DELETE FROM dbtab has the statement DELETE FROM itab with identical syntax. If an internal table has the same name as a DDIC database table, a statement like this accesses the internal table.
The statement DELETE sets a database lock as an exclusive lock until the next database commit or rollback.
NON_V5_HINTS
If used incorrectly, the latter can produce a deadlock.
ABAP_HINT_END

ABAP_VARIANT_1 DELETE FROM target ...

What does it do?
In the variant DELETE FROM target, either all rows are deleted or the rows to be deleted are restricted using a WHERE condition or additions ORDER BY, OFFSET, and UP TO.

ABAP_EXAMPLE_VX5
Deletion of a row in a DDIC database table. The row is specified using a WHERE condition.
ABEXA 00191
ABAP_EXAMPLE_END

ABAP_VARIANT_2 DELETE target FROM source.

What does it do?
In the variant DELETE target FROM, either a row specified by a work area is deleted or multiple rows specified by an internal table are deleted.

ABAP_EXAMPLE_VX5
Deletion of a row in a DDIC database table. The row is specified using a work area.
ABEXA 00192
ABAP_EXAMPLE_END

ABAP Addition

What does it do?
The addition MAPPING FROM ENTITY is used to handle structures and internal tables that are typed with BDEF derived types. Find more information in the topic ABAP SQL Statements with MAPPING FROM ENTITY.

Return to menu