Skip to content

ABAP Keyword Documentation →  ABAP − Reference →  Processing External Data →  ABAP Database Access →  ABAP SQL →  ABAP SQL - Write Accesses →  DELETE dbtab 

DELETE dbtab - source

Quick Reference

Other versions: 7.31 | 7.40 | 7.54

Syntax


... {@wa|@( expr )} 
  | {TABLE @itab|@( expr )} ...

Alternatives

1. ... @wa|@( expr )

2. ... TABLE @itab|@( expr )

Effect

In the variant DELETE target FROM of the statement DELETE, following FROM, a non-table-like data object or, following TABLE, an internal table can be specified as a host variable or host expression. 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

... @wa|@( expr )

Effect

If a non-table-like work area is specified as a host variable @wa or host expression @( expr ), 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 meet the prerequisites for use in ABAP 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.

Implicit ABAP SQL client handling applies, in which a client ID specified in wa is ignored. The current client is used by default. The addition USING CLIENT can be used to switch to an explicitly specified client. The addition CLIENT SPECIFIED can be used to switch to the client specified in wa.


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 a constructor expression is specified as a host expression for the work area wa, for which the data type is inferred using the # character, a structure consisting of the components of the primary key of the database table is created as the type.
  • 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.

Example

Deletes a carrier from the database table SCARR using a host expression.

DELETE scarr FROM @( VALUE #( carrid   = 'FF' ) ). 

Alternative 2

... TABLE @itab|@( expr )

Effect

If an internal table is specified as a host variable @itab or host expression @( expr ), the system edits all rows of the internal table in accordance with the rules for the work area wa. The row type of the internal table must meet the prerequisites for use in ABAP 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.


Notes

  • 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 DELETE.
  • If a constructor expression as a host expression is specified as an internal table itab, for which the data type is inferred using the # character, a structured standard table with an empty table key (whose row type consists of the components of the primary key of the database table) is created as the type.

Example

Deletes all today's flights of an airline in which no seats are occupied from the database table SFLIGHT. The internal table from which the key values of the deleted rows are taken is obtained in a host expression using a method call. The client field must occur in the row structure of the internal table with the type sflight_key_tab to ensure that its components match the primary key of the database table. This example works in the same way as DELETE dbtab - cond, but it requires the database to be accessed twice.

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, 
  sflight_key_tab TYPE STANDARD TABLE OF sflight_key WITH EMPTY KEY. 

CLASS sflight_methods DEFINITION. 
  PUBLIC SECTION. 
    CLASS-METHODS 
      get_empty_flights IMPORTING carrid   TYPE sflight-carrid 
                                 date     TYPE sy-datum 
                        RETURNING VALUE(r) TYPE sflight_key_tab. 
ENDCLASS. 

CLASS sflight_methods IMPLEMENTATION. 
  METHOD get_empty_flights. 
    SELECT mandt, carrid, connid, fldate 
           FROM sflight 
           WHERE carrid = @carrid AND 
                 fldate = @date AND 
                 NOT seatsocc > 0 
           INTO TABLE @r. 
  ENDMETHOD. 
ENDCLASS. 

DATA carrid TYPE sflight-carrid. 

START-OF-SELECTION. 
  cl_demo_input=>request( CHANGING field = carrid ). 

  DELETE sflight FROM TABLE @( 
    sflight_methods=>get_empty_flights( carrid = carrid 
                                       date   = sy-datum ) ).