## 4.2.15.10.3  Delete Data from the Database
The runtime to delete archived data from database should be implemented in a central ABAP class. This ABAP class must register interface IF\_ARCH\_DELETE to be able to be selected in an archiving object definition in ADT. This ABAP class can be performed within an application job [page 1501].
There are different ways to delete archived data from the database:
- Using a central delete API to delete all table entries of a data object
- Using a central delete API to delete specified tables of a data object
- Using a central delete API to get all table entries of a data object to perform an own deletion from the database
CL\_ARCH\_DELETE\_API (API for deleting archived data from the database)
| Method                                                                                           | Parameter                             | Description                                                                                |
|--------------------------------------------------------------------------------------------------|---------------------------------------|--------------------------------------------------------------------------------------------|
| GET_INSTANCE                                                                                     | Importing: IV_ARCHIVING_OBJECT        | Nameof the archiving object which will be used                                             |
| Returns an instance of the de- lete API. Reference to interface IF_ARCH_DELETE_API               | Importing: IV_ARCHIVE_KEY             | Archive key for which data should be deleted                                               |
| Returns an instance of the de- lete API. Reference to interface IF_ARCH_DELETE_API               | Importing: IV_TESTMODE                | True : no storage takes place False : Archive content is written, and storage is requested |
| Returns an instance of the de- lete API. Reference to interface IF_ARCH_DELETE_API               | Returning: RO_DELETE_INSTANCE         | Instance of the delete API                                                                 |
| GET_FILES_TO_DELETE Returns a table with archive keys which have not yet been processed by dele- | Importing: IV_ARCHIVING_OBJECT        | Nameof the archiving object which will be used                                             |
| tion                                                                                             | Importing: IT_DATE_SELECTION          | Range of dates on which archive files have been created                                    |
| tion                                                                                             | ReturnsImporting: IT_USER_SELECTION   | Range of users which have created ar- chive files                                          |
| tion                                                                                             | Returning: RT_ARCHIVE_FILE_ATTRIBUTES | Table of archive keys which fulfill the selection criteria for dates and users             |
## IF\_ARCH\_DELETE\_API (Interface for deleting archived data from the database)
| Method                                                             | Parameter                       | Description                                                                                                                                                                   |
|--------------------------------------------------------------------|---------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| GET_NEXT_OBJECT Reads the next data object for the ar- chived data | Exporting: EV_OBJECT_OFSET      | Offset at which the data of the data ob- ject starts. This can be used to build ap- plication-owned indices for the archived data.                                            |
| GET_NEXT_OBJECT Reads the next data object for the ar- chived data | Exporting: EV_ARCHIVE_KEY       | Archive key of the archive file to which the data was written. This can be used to build application-owned indices for the archived data.                                     |
| GET_NEXT_OBJECT Reads the next data object for the ar- chived data | Exporting: EV_ARCHIVING_SESSION | Sessions of the archiving object which will be used                                                                                                                           |
| GET_NEXT_OBJECT Reads the next data object for the ar- chived data | Exporting: EV_END_OF_FILE       | True : All data contained in the files is processed, and the application should finalize the deletion False : The application should continue processing the next data object |
| GET_DATA_RECORDS                                                   | Importing: IV_RECORD_STRUCTURE  | Nameof the table for which archived data should be returned                                                                                                                   |
| GET_DATA_RECORDS                                                   | Exporting: ET_DATA_RECORDS      | Records of the table                                                                                                                                                          |
| DELETE_DATA_FOR_TABLE Deletes the data for a specific table        | Importing: IV_TABLE_NAME        | Nameof the table for which archived data should be deleted                                                                                                                    |
| from the database                                                  | Importing: IT_RECORDS           | Records of the table to be deleted                                                                                                                                            |
## DELETE\_DATA\_FOR\_OBJECT
Deletes all table entries contained in the data object
## FINALIZE
Finalizes processing
Typical flow of the archiving delete process:
1. Determine files which are still available for deletion by using the method CL\_ARCH\_DELETE\_API=&gt; GET\_FILES\_TO\_DELETE , with filter options on creating user and creation date of the archive file.
2. Create an instance of the delete API and open the archiving delete session for one of the selected archive files by using method CL\_ARCH\_DELETE\_API=&gt;GET\_INSTANCE .
3. Open the next data object with the method GET\_NEXT\_DATA\_OBJECT . If the method returns EV\_END\_OF\_FILE = TRUE ('X') , continue with step 6. Optional (can be used for reading archived data via index access): Update the index table with the data object archived.
4. Delete the data of the object from your database tables either by:
- Use of the method DELETE\_DATA\_FOR\_OBJECT
- Use of the method DELETE\_DATA\_FOR\_TABLE . Call this method once for each table.
- Use of the method GET\_DATA\_RECORDS . Use the result to perform your own DELETE statements.
5. Continue with the next data object. See step 3.
6. Finish the archiving delete session by calling the method FINALIZE .
##  Sample Code
```
CONSTANTS: lc_object TYPE if_arch_api_types=>ty_object_name VALUE 'MY_OBJECT'. DATA:  lv_test TYPE abap_bool VALUE abap_true, lt_data TYPE STANDARD TABLE OF my_index_table, lv_arkey TYPE sarch_archive_key. DATA:   ls_index TYPE my_index_table. " get newest undeleted file DATA(lt_files) = cl_arch_delete_api=>get_files_to_delete( iv_archiving_object = lc_object ). SORT lt_files BY creation_date DESCENDING creation_time DESCENDING. READ TABLE lt_files ASSIGNING FIELD-SYMBOL(<ls_file>) INDEX 1. DATA(lo_delete) = cl_arch_delete_api=>get_instance ( iv_archiving_object = lc_object iv_archive_key = lv_arkey iv_testmode = lv_test ). " read next data object from archive file into internal memory DO. lo_delete->get_next_data_object( IMPORTING ev_end_of_file = DATA(lv_end_of_file) ev_archive_key = DATA(lv_archive_key) ev_object_offset = DATA(lv_offset) ). IF lv_end_of_file = abap_true. EXIT. ENDIF.
```
```
" optional: Create customer owned index for single document access during read " read archived data for table MY_HEADER_TABLE lo_delete->get_data_records( EXPORTING iv_record_structure = 'MY_HEADER_TABLE' IMPORTING et_data_records = lt_data ). " map flight data to your index table MY_INDEX_TABLE IF lv_test <> abap_true. LOOP AT lt_data ASSIGNING FIELD-SYMBOL(<ls_data>). MOVE-CORRESPONDING <ls_data> TO ls_index. Ls_index-archive_key = lv_archive_key. Ls_index-archive_offset = lv_offset. INSERT my_index_table FROM @ls_Index. ENDLOOP. ENDIF. " delete the data from the data base lo_delete->delete_data_for_object( ). ENDDO. COMMIT WORK. lo_delete->finalize( ).
```
Example of a customer-owned index table for archived flights:
## 
```
Sample Code @EndUserText.label : 'Archiving Index: Flights' @AbapCatalog.enhancement.category : #NOT_EXTENSIBLE @AbapCatalog.tableCategory : #TRANSPARENT @AbapCatalog.deliveryClass : #A @AbapCatalog.dataMaintenance : #ALLOWED define table my_index_table { @EndUserText.label : 'Client' key mandt : abap.clnt not null; @EndUserText.label : 'Airline Code' key carrid : abap.char(3) not null; @EndUserText.label : 'Flight Connection Number' key connid : abap.numc(4) not null; @EndUserText.label : 'Flight date' key fldate : abap.dats not null; archive_key : sarch_archive_key; archive_offset : sarch_offset;
```