Skip to content

ABAP Keyword Documentation →  ABAP - Reference →  Processing External Data →  ABAP Database Accesses →  Open SQL →  Open SQL - Writes →  DELETE dbtab 

DELETE dbtab - source

Short Reference

Other versions: 7.31 | 7.40 | 7.54

Syntax


... FROM wa|{TABLE itab}. 

Alternatives

1. ... FROM wa
2. ... FROM TABLE itab

Effect

A wa data object that is not table-like or an itab internal table can be specified after FROM. The content of the data objects determines the row(s) to be deleted. The escape character @ should precede the work area name or the internal table name (as should be the case with every host variable).


Note

Host variables without the escape character @ are obsolete. The escape character @ must be specified in the strict modes of the syntax check from Release 7.40, SP05.

Alternative 1

... FROM wa

Effect

If a work area wa is specified that is not table-like, a row is found 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 fulfill 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.

By default, an automatic client handling is performed, which means that a client identifier specified in wa is not considered, but the current client is used instead. This has no effect on wa. Automatic client handling can be switched off using the addition CLIENT SPECIFIED.


Notes

  • The work area wa should be declared with reference to the database table or view in ABAP Dictionary using the length of the primary key.
  • If the database table or view is specified statically, a short form can be specified outside of classes. This means that the work area specified using FROM wa can be omitted. The prerequisite is that a table work area dbtab for the respective database table or the view is declared using the statement TABLES. The system then implicitly adds the addition FROM dbtab 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 fulfill the prerequisites for use in Open SQL statements.

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


Note

When an internal table is used, package-by-package processing causes some of the rows being deleted to still be visible to any read access running in parallel with the DELETE.


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. However, since the client column of the internal table is not supplied with values, the warning from the syntax check must be hidden by the relevant pragma. This example works in the same way as DELETE dbtab - cond, but it requires the database to be accessed twice. 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 
       WHERE carrid = @p_carrid AND 
             fldate = @sy-datum AND 
             seatsocc = 0 ##too_many_itab_fields. 
       INTO CORRESPONDING FIELDS OF TABLE @sflight_key_tab. 

DELETE sflight FROM TABLE @sflight_key_tab.