SAP ABAP Deleting Internal Tables - SAP ABAP

What is the process of deleting tables in sap abap? What type of statements are used?

As the name specifies that the DELETE statement is used to delete one or more records from an internal table. in order to delete the records of an internal table, you need to use a specific table key or other alternative is that finding duplicate entries. So, in other aspects if an internal table has a non-unique key and contains duplicate entries, the first entry from the table is to be deleted.

Following is the syntax to use the DELETE statement to delete a record or line from an internal table −

In the above syntax, the <work_area_itab> expression is a work area and it should match with the type of the <internal_table> internal table (as you have seen in reading the table statements.) The delete operation is performed by using the default key that could be taken from the work area components.

You may also specify a table key explicitly in the DELETE TABLE statement by using the following syntax −

In the following syntax, <F1>, <F2>....<Fn> are the fields of an internal table and <K1>, <K2>....<Kn> are the key fields of the table. The DELETE statement is performed to delete the records or lines of the <internal_table> table based on the expressions <K1> = <F1>, <K2> = <F2>...<Kn> = <Fn>.

Note − If the data types of the <F1>, <F2>....<Fn> fields does not match with the <K1>, <K2>...<Kn> key fields then the SAP system has the ability to convert them into the compatible format automatically.

Example

The above code produces the following output −

In this example, mytable has two fields, ColP and ColQ. Initially, mytable is populated with eight lines, where the ColP contains the values 1, 2, 3, 4, 5, 6, 7 and 8. The ColQ contains the values 5, 6, 7, 8, 9, 10, 11 and 12 because the ColP values are incremented by 4 every time.

The DELETE statement is used to delete the lines from my table with the specified value of the ColP key field is either 1 or 3. After deletion is completed, the ColP field of my table contains the values 2, 4, 5, 6, 7 and 8, as shown in the output. The ColQ field contains the values 6, 8, 9, 10, 11 and 12.

All rights reserved © 2020 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

SAP ABAP Topics