SAP DELETE ITAB INDEX ABAP Statements



Get Example source ABAP code based on a different SAP table
  


• • DELETE itab

DELETE itab, index
Short Reference

ABAP_SYNTAX
... ${ itab • idx $[USING KEY keyname$] $}
$| ${ itab $[USING KEY loop_key$]$} ...

ABAP_ALTERNATIVES:
1 ... itab • idx $[USING KEY keyname$]
2 ... itab $[USING KEY loop_key$]

What does it do?
These alternatives specify the lines to be deleted using the specification of a line number relating to a table index.

ABAP Alternative 1 ... itab • idx

ABAP Addition
... USING KEY keyname

What does it do?
If the • addition is used, the DELETE statement deletes the line in the line number specified in idx in a table index. idx is a numeric expression position with the operand type i. If idx contains the value 0 or less, an uncatchable exception is raised.
If the addition USING KEY is not used, the addition • can only be used with index tables and determines the line to be deleted from the primary table index.

ABAP_EXAMPLE_VX5
Deletion of the table line that has the same value as the input field carrid in the key field carrid, by using the primary table index.
ABEXA 00199
ABAP_EXAMPLE_END

ABAP_EXAMPLE_ABEXA
Deleting Lines Using an Index
ABAP_EXAMPLE_END
• USING KEY DELETE itab •

ABAP Addition

What does it do?
The addition USING KEY can be used to specify a table key can be specified in keyname to specify the table index to be used explicitly.
If the table has a sorted secondary key, this can be specified in keyname. The line to be deleted is then determined from its secondary table index. A secondary hash key cannot be specified.
If the primary table key is specified under its name primary_key, the table must be an index table, and the behavior is the same as when USING KEY is not specified.



Latest notes:

If a sorted secondary key exists, the • addition can be used for all table types, if USING KEY is used.
NON_V5_HINTS
ABAP_HINT_END

ABAP_EXAMPLE_VX5
The DELETE statement deletes the third line of the internal table, since this has the line number 1 in the secondary table index belonging to the secondary table key skey.
ABEXA 00200
ABAP_EXAMPLE_END

ABAP Alternative 2 ... itab

ABAP Addition
... USING KEY loop_key

What does it do?
This variant is only possible within a LOOP across the same internal table. The current table line of the LOOP is then deleted implicitly. If the addition USING KEY is specified in LOOP , the addition USING KEY loop_key must be specified for this variant.
If the current line was already deleted in the same loop, however, the behavior is undefined.
This variant is not allowed outside of a LOOP and raises a warning in the syntax check if it is not known statically that is executed in a loop.



Latest notes:

This alternative is not recommended. Instead, use the addition • to specify the line number explicitly.
NON_V5_HINTS
ABAP_HINT_END

ABAP_EXAMPLE_VX5
The following loop deletes all lines of an internal table, since the short form of the statement DELETE always deletes the current first line.
ABEXA 00201
ABAP_EXAMPLE_END

ABAP Addition

What does it do?
This addition is required if the table key used by the LOOP is specified explicitly in the statement LOOP. It states explicitly that the current table line is deleted by the LOOP. No other key can be specified apart from the predefined name loop_key. If no explicit table key is specified for LOOP, the addition USING KEY loop_key is optional.

ABAP_EXAMPLE_VX5
Since the primary table key is specified explicitly for the LOOP loop, USING KEY loop_key must be specified for DELETE as well.
ABEXA 00202
ABAP_EXAMPLE_END

Return to menu