How to Delete from Internal Table using ABAP
As an ABAP developer, I frequently require to delete an entry from an internal table using ABAP codes.
I believe this is a common task and many developers requires simple ABAP commands to delete from internal table, or remove entries from an ABAP internal table.
Here is the two methods I frequently use to delete from internal table.
The below ABAP code block deletes entries from internal table gt_result where field langu has a different value other than p_langu selection parameter has.
DELETE gt_result WHERE langu NE p_langu.
Using the following ABAP script, developers can also delete or remove unwanted rows from an internal table.
But the following DELETE structure has a loop mechanism.
By looping in the internal table entries, the ABAP code checks a certain condition. If the condition occurs then the DELETE ABAP command removes the current loop item from internal table.
The key point in this code is using "INDEX sy-tabix" hint which points to the index of the current loop item.
LOOP AT gt_result INTO gwa_search.
IF gwa_search-sysid NE p_sapsys.
DELETE gt_result INDEX sy-tabix.
ENDIF.
ENDLOOP.
|