DELETE : ABAP Keyword a day
DELETE
Delete from a database table
– DELETE FROM dbtab WHERE condition.
– DELETE FROM (dbtabname) WHERE condition.
– DELETE dbtab.
– DELETE *dbtab.
– DELETE (dbtabname) … .
– DELETE dbtab FROM TABLE itab.
– DELETE (dbtabname) FROM TABLE itab.
– DELETE dbtab VERSION vers.
– DELETE *dbtab VERSION vers.
Delete from an internal table
– DELETE itab.
– DELETE itab INDEX idx.
– DELETE itab FROM idx1 TO idx2.
– DELETE itab WHERE condition.
– DELETE ADJACENT DUPLICATES FROM itab.
Delete a program
– DELETE REPORT prog.
Delete text elements
– DELETE TEXTPOOL prog LANGUAGE lg.
Delete a data cluster
– DELETE FROM DATABASE dbtab(ar) …ID key.
Delete a file
– DELETE DATASET dsn.
Delete a screen
– DELETE DYNPRO f.
DELETE – Delete from a database table
Variants
1. DELETE FROM dbtab WHERE condition.
DELETE FROM (dbtabname) WHERE condition.
2. DELETE dbtab.
DELETE *dbtab.
DELETE (dbtabname) …
3. DELETE dbtab FROM TABLE itab.
DELETE (dbtabname) FROM TABLE itab.
4. DELETE dbtab VERSION vers.
DELETE *dbtab VERSION vers.
Effect
Deletes lines in a database table . You can specify the name of the database table either in the program itself with DELETE FROM dbtab … or at runtime as the contents of the field dbtabname with DELETE FROM (dbtabname) … . In both cases, the database table must be known in the ABAP/4 Dictionary. If you specify the name in the program, there must also be an appropriate TABLES statement. Only data from the current client is usually deleted. You can delete data using a view only if the view refers to a single table and was created in the ABAP/4 Dictionary with the maintenance status “No restriction”.
DELETE belongs to the Open SQL command set.
Note
The DELETE statement does not perform authorization checks : You must program these yourself.
Variant 1
DELETE FROM dbtab WHERE condition.
DELETE FROM (dbtabname) WHERE condition.
Addition
… CLIENT SPECIFIED
Effect
Deletes lines in a database table that satisfy the WHERE clause condition . With this variant, specification of a WHERE condition is obligatory .
When the statement has been executed, the system field SY-DBCNT contains the number of deleted lines.
The return code value is set as follows:
SY-SUBRC = 0 At least one line was deleted.
SY_SUBRC = 4 No lines were deleted, since no line was selected.
Example
Delete all bookings for the Lufthansa flight 0400 on 28.02.1995 (in the current client):
TABLES SBOOK.
DELETE FROM SBOOK WHERE CARRID = ‘LH’ AND
CONNID = ‘0400’ AND
FLDATE = ‘19950228’.
Note
To delete all the lines in a table, you must specify a WHERE condition that is true for all lines. You can achieve this with
… WHERE f IN itab
If the internal table itab is empty, such a condition would select all lines.
Addition
… CLIENT SPECIFIED
Effect
Switches off automatic client handling. This allows you to delete data across all clients in the case of client-specific tables. The client field is then treated like a normal table field, for which you can formulate suitable conditions in the WHERE clause.
You must specify the addition CLIENT SPECIFIED immediately after the name of the database table.
Variant 2
DELETE dbtab.
DELETE *dbtab.
DELETE (dbtabname) …
Additions
1. … FROM wa
2. … CLIENT SPECIFIED
Effect
These are SAP-specific short forms used to delete a single line of a database table. If the name of the database table is specified in the program, the primary key of the line to be deleted is taken from the specified work area – dbtab or *dbtab . If the name of the database table is not determined until runtime ( DELETE (dbtabname) … ), the addition … FROM wa is obligatory .
When the statement has been executed, the system field SY-DBCNT contains the number of deleted lines (0 or 1).
The return code value is set as follows:
SY-SUBRC = 0 The line was deleted.
SY_SUBRC = 4 No lines could be deleted, since no line exists with the primary key specified.
Example
Delete the booking with the booking number 3 for the Lufthansa flight 0400 on 28.02.1995 (in the current client):
TABLES SBOOK.
SBOOK-CARRID = ‘LH’.
SBOOK-CONNID = ‘0400’.
SBOOK-FLDATE = ‘19950228’.
SBOOK-BOOKID = ‘00000003’.
DELETE SBOOK.
Addition 1
… FROM wa
Effect
Takes the primary key for the line to be deleted not from the table work area dbtab , but from the explicitly specified work area wa . Here, the key values from left to right are taken from wa according to the structure of the primary key in the table work area dbtab (see TABLES ). The structure of wa is not taken into account. Therefore, the work area wa must be at least as wide (see DATA ) as the primary key in the table work area dbtab and the alignment of the work area wa must correspond to the alignment of the primary key in the table work area. Otherwise, you get a runtime error.
Note
If a work area is not explicitly specified, the values for the line to be deleted are taken from the table work area dbtab , even if the statement appears in a subroutine (see FORM ) or Funktionsbaustein (see FUNCTION ) where the table work area is stored in a formal parameter or a local variable of the same name.
Addition 2
… CLIENT SPECIFIED
Effect
As with variant 1.
Variant 3
DELETE dbtab FROM TABLE itab.
DELETE (dbtabname) FROM TABLE itab.
Addition
… CLIENT SPECIFIED
Effect
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.
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 value 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.
Addition
… CLIENT SPECIFIED
Effect
As with variant 1.
Variant 4
DELETE dbtab VERSION vers.
DELETE *dbtab VERSION vers.
Note
This variant is obsolete, since variants 1 – 3 allow you to specify the database table name dynamically.
Effect
Deletes a line in a database table, the name of which is taken from the field vers at runtime. The database table must be known to the ABAP/4 Dictionary and its name must conform to the following naming convention: It must begin with ‘T’ and can consist of four additional characters. The field vers must contain the table name without a leading ‘T’. Only lines in the current client are deleted. The line to be deleted is taken from the statically specified table work area dbtab or *dbtab .
The return code value is set as follows:
SY-SUBRC = 0 The line was deleted.
SY_SUBRC = 4 No lines could be deleted because no line existed with the specified primary key.
***********************************************
DELETE – Delete from an internal table
Variants
1. DELETE itab.
2. DELETE itab INDEX idx.
3. DELETE itab FROM idx1 TO idx2.
4. DELETE itab WHERE condition.
5. DELETE ADJACENT DUPLICATES FROM itab.
Effect
Deletes one or more lines from an internal table.
Note
The deletion of lines within a LOOP … ENDLOOP loop is performed in a sequence of loop passes.
Variant 1
DELETE itab.
Effect
The current entry of the internal table itab is
deleted in a LOOP loop.
Return code value
The is set to 0.
Note
After deleting the current entry in an internal table in a LOOP loop, the effect of further update operations on the current entry without an INDEX specification is not guaranteed and may changed in later Releases.
Variant 2
DELETE itab INDEX idx.
Effect
Deletes the idx entry from the internal table itab .
The return code value is set as follows:
SY-SUBRC = 0 The entry was deleted.
SY_SUBRC = 4 The entry does not exist.
Variant 3
DELETE itab FROM idx1 TO idx2.
Effect
Deletes the line area from index idx1 to idx2 from internal table itab . At least one of the two parameters FROM idx1 or TO idx2 should be specified. If parameter FROM is missing, the area from the start of the table to line idx2 is deleted. If parameter TO is missing, the area from line idx1 to the end of the table is deleted. Start index idx1 must be greater than 0.
The return code value is set as follows:
SY-SUBRC = 0 At least one entry was deleted.
SY_SUBRC = 4 None of the entries were deleted.
Variant 4
DELETE itab WHERE condition.
Additions
1. … FROM idx1
2. … TO idx2
Effect
Deletes all entries from internal table itab , which satisfies the condition condition .
The return code value is set as follows:
SY-SUBRC = 0 At least one entry was deleted.
SY_SUBRC = 4 None of the entries were deleted.
Addition 1
… FROM idx1
Effect
The line area to be investigated is restricted to the lines up to index idx1 . If the addition FROM idx1 is missing, a search is carried out from the beginning of the table.
The addition FROM must come before the WHERE condition.
Addition 2
… TO idx2
Effect
Restricts the line area to be investigated to the lines up to index idx2 . If the addition TO idx2 is missing, a search is carried out until the end of the table.
The addition TO must come before the WHERE condition.
Example
Delete all lines in a name table between lines 5 and 36, if the entry begins with one of the letters ‘A’ to ‘C’ :
DATA: BEGIN OF NAMETAB OCCURS 100,
NAME(30) TYPE C, END OF NAMETAB.
…
DELETE NAMETAB FROM 5 TO 36 WHERE NAME CA ‘ABC’.
Variant 5
DELETE ADJACENT DUPLICATES FROM itab.
Additions
1. … COMPARING f1 f2 …
2. … COMPARING ALL FIELDS
Effect
Deletes neighboring, duplicate entries from the internal table itab . If there are n duplicate entries, the first entry is retained and the other n – 1 entries are deleted.
Two lines are considered to be duplicated if their default keys match.
The return code value is set as follows:
SY-SUBRC = 0 At least one duplicate exists, at least one entry deleted.
SY_SUBRC = 4 No duplicates exist, no entry deleted.
Addition 1
… COMPARING f1 f2 …
Effect
Two lines of the internal table itab are considered to be duplicates if the specified fields f1 , f2 , …. match.
Addition 2
… COMPARING ALL FIELDS
Effect
Two lines are considered to be duplicates if all fields of the table entries match.
Notes
The DELETE ADJACENT DUPLICATES statement is especially useful if the internal table itab is sorted by fields (whether in ascending or descending order) which were compared during duplicate determination. In this case, the deletion of neighbouring duplicates is the same as the deletion of all duplicates.
If a comparison criterion is only known at runtime, it can be specified dynamically as the content of a field name by using COMPARING … (name) … . If name is blank at runtime, the comparison criterion is ignored. If name contains an invalid component name, a runtime error occurs.
Comparison criteria – statistically or dynamically specified – can be further restriced by specifying the offset and/or length.
Note
Performance
Deleting a line from an internal table incurs index maintenance costs which depend on the index of the line to be deleted. The runtime depends on the line width of the table.
For example, deleting a line in the middle of an internal table with 200 entries requires about 10 msn (standardized microseconds).
Deleting a range of entries with ” DELETE itab FROM idx1 TO idx2. ” deleting a set of entries with ” DELETE itab WHERE … ” only incur index maintenance costs once. Compared with a LOOP , which deletes line-by-line, this is much faster.
To delete neighboring, duplicate entries from an internal table, use the variant ” DELETE ADJACENT DUPLICATES FROM itab. ” instead of LOOP constructions.
Related INSERT itab , MODIFY itab
***********************************************
DELETE – delete a program
Basic form
DELETE REPORT prog.
Effect
Deletes some components (source code, attributes, text elements and generated version) of the program specified in the field prog .
The return code value is set as follows:
SY-SUBRC = 0 The program was deleted.
SY_SUBRC = 4 The program does not exist.
Note
This statement deletes neither the variants nor the documentation.
Normally, you should use the function module RS_DELETE_PROGRAM to delete a program.
Related INSERT REPORT , DELETE TEXTPOOL
***********************************************
DELETE – delete text elements
Basic form
DELETE TEXTPOOL prog LANGUAGE lg.
Effect
Deletes all text elements of the program specified in the field prog for the language specified in the field lg from the library.
If you use the value ‘*’ for lg , the text elements of all languages are deleted.
Example
Delete all text elements of the program PROGNAME in the language “English”:
DATA: PROGRAM(8) VALUE ‘PROGNAME’.
DELETE TEXTPOOL PROGRAM LANGUAGE ‘E’.
Related INSERT TEXTPOOL , READ TEXTPOOL
***********************************************
DELETE – delete a data cluster
Basic form
DELETE FROM DATABASE dbtab(ar) ID key.
Addition
… CLIENT f
Effect
Deletes the data cluster stored in the table dbtab under the area ar (constant) and the ID key (field or literal) (EXPORT … TO DATABASE … ).
Example
TABLES INDX.
DATA: BEGIN OF TAB OCCURS 1,
CONT(30),
END OF TAB.
DATA: FLD(30) TYPE C.
…
EXPORT TAB FLD TO DATABASE INDX(AR) ID ‘TEST’.
You can delete this data cluster with the following statement:
DELETE FROM DATABASE INDX(AR) ID ‘TEST’.
Addition 1
… CLIENT f
Effect
Deletes the data cluster in the client specified in the table f (only with client-specific import/export databases).
Example
TABLES INDX.
DELETE FROM DATABASE INDX(AR) CLIENT ‘001’ ID ‘TEST’.
***********************************************
DELETE – delete a file
Basic form
DELETE DATASET dsn.
Effect
Deletes the file specified in the field dsn .
The return code value is set as follows:
SY-SUBRC = 0 File deleted.
SY_SUBRC = 4 File does not exist or could not be deleted.
Possible reasons:
1) The file does not exist. 2) The file is a directory. 3) The R/3 System has no search authorization
for a component of the file name. 4) The R/3 System has no search authorization
for the directory which contains the file. 5) A component of the search path is not a
directory. 6) The file is a symbolic link which cannot be
resolved (endless loop ?). 7) The file is a program which is currently
running.
Related OPEN DATASET , READ DATASET , CLOSE .
***********************************************
DELETE DYNPRO – delete a screen
Basic form
DELETE DYNPRO f.
Effect
Deletes the screen specified in the field f .
The return code value is set as follows:
SY-SUBRC = 0 The screen was deleted.
SY_SUBRC = 4 The screen does not exist.
The contents of f consist of the 8-character program name and the 4-character screen number.
Example
DELETE DYNPRO ‘SAPTESTX0100’.
Related IMPORT DYNPRO , EXPORT DYNPRO , GENERATE DYNPRO , SYNTAX-CHECK FOR DYNPRO .