Developing Delete Programs

Use

For data security reasons, the write program must not delete any data in the database. During the delete phase, a separate delete program deletes the data from the database. This ensures that no data can be lost during the write phase, and makes online archiving possible.

The delete program reads the archive files using the ADK function modules (FM) and then deletes the data from the database. A delete program always only processes one archive file at a time. Several delete programs can run in parallel, each processing one archive file.

Important Information

  • You can also create delete program test and production mode variants in archiving-object-specific Customizing.
  • The delete programs determine which data is to be deleted from the database by reading the archive files. This guarantees that only data that can successfully be read from the archive files is deleted from the database.
  • The delete programs must use function module ARCHIVE_GET_CUSTOMIZING_DATA to get the value of the object counter, which controls after how many data objects a COMMIT WORK is called by the delete program.

The Unicode-enabled ADK requires certain changes in existing delete programs, specifically for ARCHIVE_GET_NEXT_RECORD. Of course, these new guidelines must also be followed for new delete programs you develop.

Procedure

Function Module Call Sequence

  1. Initialize delete – ARCHIVE_OPEN_FOR_DELETE

This function module:

      • Opens the archive file for reading
      • Provides an archive handle for archive access
      • Includes all archiving classes listed in the archive file
      • In production mode, sets the status information in archive management
  1. Get commit counter – ARCHIVE_GET_CUSTOMIZING_DATA

You use this function module to get the commit counter set in Customizing in transaction AOBJ.

  1. (Optional): Get structures for initialization data – ARCHIVE_GET_INIT_STRUCTURES

As of SAP Web Application Server 6.10, you use this function module to get the structures of the initialization data you passed in the write program using ARCHIVE_PUT_INIT_DATA.

  1. (Optional) Get initialization data – ARCHIVE_GET_INIT_DATA

As of SAP Web Application Server 6.10, you use this function module to get the initialization data you passed in the write program using ARCHIVE_PUT_INIT_DATA.

The following steps (5 - 8) must be called in a loop for all data objects to be deleted.

  1. Read next data object from archive file – ARCHIVE_GET_NEXT_OBJECT

You use this function module to read the next data object from the archive file opened for deleting.

This function module:

      • Reads archived data objects from the archive file into the ADK container
      • For archiving class data, passes the data to the archiving class

The parameter OBJECT_ID must syntactically be CHAR.

  1. Tell archiving classes to delete their data – ARCHIVE_DELETE_OBJECT_DATA

This function module must be called after every ARCHIVE_GET_NEXT_OBJECT and cannot be grouped according to < commit counter > data objects.

  1. Get archiving object data – ARCHIVE_GET_NEXT_RECORD (or ARCHIVE_GET_TABLE where it makes sense)

You use this function module to get the archiving object data from ADK’s data container and store the data in an internal table for each structure or table. Call this function module in a loop within the loop started in step 5 until no more records can be read from ADK’s data container.

If your write program stored information in the RECORD_FLAGS field, you can use this information in the delete program to determine which data should actually be deleted from the database.

In the Unicode context, there are two possibilities for calling this function module:

    • Assign typed field symbols to the reference returned using the new parameter RECORD_REF
      (example: SBOOKR)
    • Assign untyped field symbols
      (example: SBOOKR_2)

In the Unicode context, it is no longer possible to use the CHAR record buffer variable for generic reading of records for structures containing non-character-like fields.

  1. Delete archiving object data from the database – Separate subroutine you develop

After each ARCHIVE_GET_NEXT_OBJECT, increase a counter by one. When the delete program is running in production mode, call your subroutine whenever the counter is equal to the Commit Counter set in Customizing. In test mode, do not call this subroutine.

Your subroutine must:

    1. Read the internal tables and delete that data from the database
    2. Call ARCHIVE_GIVE_STATISTICS to pass the number of records deleted to ADK; to determine the number of records deleted, use the parameter SY-DBCNT

      You must call this function module. Otherwise the statistics function will not work correctly.

    3. Call COMMIT WORK and clear the internal tables
    4. Clear the counter

End of loop

  1. (Optional) Get statistics from ADK – ARCHIVE_GET_STATISTICS

In delete programs, ARCHIVE_GET_STATISTICS only works in production mode.

You use this function module to get the statistics ADK collected. You can then use these statistics to create your own specialized log. This function module can be used in addition to ARCHIVE_WRITE_STATISTICS or on its own.

  1. (Optional) Output standard statistics log – ARCHIVE_WRITE_STATISTICS

In delete programs, ARCHIVE_WRITE_STATISTICS only works in production mode.

You use this function module to output the standard archiving statistics log with the relevant information for the delete program. This function module must be called directly before ARCHIVE_CLOSE_FILE.

  1. End delete phase – ARCHIVE_CLOSE_FILE

This function module:

      • Closes the archive file
      • Releases the included archiving classes
      • Discards the current archive handle
      • Passes the archive file to the SAP Content Management Infrastructure (if set in Customizing)

Result

When you finish developing your delete program, enter it for your archiving object in transaction AOBJ.

Example

Sample programs SBOOKD and SFLIGHTD (for use of archiving classes)