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.
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.
Following ABAP code block populates an internal table with sample data. After then using an ABAP Loop command, each internal table row is processed. In case the internal table text is not matching a criteria, the internal table row is deleted using the "Delete itable Index sy-tabix" ABAP command.
Here is the ABAP code illustrated in above screenshot where you can use to delete internal table row within a Loop command.