DELETE dbtab - source
Short Reference
ABAP Syntax ... FROM wa|{TABLE itab}.
ABAP_ALTERNATIVES:
1 ... FROM wa
2 ... FROM TABLE itab
What does it do? A wa data object that is not table-type or an
itab internal table can be specified after FROM . The content
of the data objects determines the row(s) to be deleted.
ABAP_ALTERNATIVE_1 ... FROM wa
What does it do? 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
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 . You can switch off automatic client
handling using the addition CLIENT SPECIFIED
.
Latest notes: The work area wa should be declared with reference
to the database table or view in the ABAP Dictionary using the length of
the primary key.
If you have a static specification of the database table or the view,
a short form of the specification outside of
classes is possible. This means that the specification of the work area
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 FROM dbtab
addition to the DELETE statement.
ABAP_ALTERNATIVE_2 ... FROM TABLE itab
What does it do? 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.
Latest 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 the DELETE .
Example ABAP Coding
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
INTO CORRESPONDING FIELDS OF TABLE sflight_key_tab
WHERE carrid = p_carrid AND
fldate = sy-datum AND
seatsocc = 0 ##too_many_itab_fields.
DELETE sflight FROM TABLE sflight_key_tab.
Documentation extract taken from SAP system, � Copyright SAP AG. All rights reserved