DELETE itab

DELETE - Delete from an internal table

Variants:

1. DELETE itab.
2. DELETE itab WITH TABLE KEY k1 = v1 ... kn = vn.
3. DELETE itab [FROM wa].
4. DELETE itab INDEX idx.
5. DELETE itab FROM idx1 TO idx2.

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.

Effect

The current entry of the internal table itab is deleted in a LOOP loop. You can only use this variant with index tables (standard or sorted tables).

The

return code

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 TABLE itab WITH TABLE KEY k1 = v1 ... kn = vn.

Effect

Deletes a record from an

internal table. You can use this variant for any table. The variant is a single record command that deletes the table record with the key values k1 = v1 ... kn 0 vn . If there is more than one record with the specified key values, the system deletes the first one that it finds. You must specify the table key completely. Each part of the key ki must be compatible with its value vi. If you do not know a value until runtime, you can specify it dynamically as the contents of the field fi.

The runtime cost for deleting a record from a table depends on the table type:

Standard tables (STANDARD TABLE):

The system searches for the record beginning at the start of the table. The runtime requirement is linear.

Sorted tables (SORTED TABLE):

The system searches using the table key. The runtime requirement is logarithmic.

Hash tables (HASHED TABLE):

The system searches for the record using the table key and the hash administration. The runtime required is constant. In tables where records have been deleted, there is a preceding entry/following entry procedure. The hash administration completes the first delete command, for which the runtime requirement is linear. Deletion increases the required space for each table entry by 8 bytes.

Effect

This variant is similar to variant 2. The values for the table key are taken from the corresponding subfields of the (structured) field wa. wa must be compatible with the line type of itab. This variant allows you to DELETE without using a statically-declared tyble key. If you are deleting from a table with header line, you can omit the FROM wa. In this case, the key values are taken from the header line.

Effect

The system deletes the idx-th entry from the internal table. You can only use this variant with index tables (standard or sorted tables).

Effect

Deletes the line area from index idx1 to idx2 from internal table itab. You can only use this variant with index tables (standard or sorted tables). 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.

1. ... FROM idx1
2. ... TO idx2

Effect

Deletes all entries from internal table itab, which satisfies the condition logeexp.

logexp can be almost any logical expression. Its only restriction is that the first field in each comparison must be a subfield of the line structure of the internal table. You can only use the additions ... FROM idx1 or ... TO idx2 with index tables (standard or sorted tables).

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.

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'.

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 keys match.

SY-SUBRC = 0:

At least one duplicate exists, at least one entry deleted.

Effect

Two lines of the internal table itab are considered to be duplicates if the specified fields f1, f2, .... match.

Effect

Two lines are considered to be duplicates if all fields of the table entries match.

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.

Related

INSERT itab, MODIFY itab