
Developing Archiving Programs
Purpose
Archiving programs write the data to an archiving object in an archive file. These programs can be adjusted to individual requirements. The data objects to be archived can either be called directly in the archiving program or through a logical database.
All archiving programs have one thing in common. They use the ADK function modules (function group ARCH), to save their data by objects in archive files. All archive file access methods are covered by these function modules (see also
Standard Archiving Programs)
.For the development of archiving programs it is also advantageous if archiving classes are defined. These contain the program logic for the data transfer between the database and the data container (see also
Archiving Using Archiving Classes)
. If no archiving classes exist, the archiving program must get the data from the database. The data is passed to the data container through the ADK standard class.
Guidelines
To avoid loss of data, the archiving program must not delete any data in the database itself. (Deletion is performed by an independent delete program.)
The archiving program can change the database, to set an archiving indicator, for example. This should only happen when absolutely necessary, as every change increases the database load and the archiving runtime.
As archiving programs run in online operation, the data selection should not severely affect performance of the R/3 System.
Every time the ADK creates a new archive file a COMMIT (not the ABAP command COMMIT WORK) is sent to the database.

For detailed information about ADK function modules, see
Function Modules.
Process Flow
Function modules call sequence
Open archiving – ARCHIVE_OPEN_FOR_WRITE
This archiving object function module is called once only for each archiving session (per archiving object) and returns a unique handle which is required for all further archive operations. The function module performs the following tasks for the archiving object passed:
- Controls whether an archive file is to be created
- Controls whether the delete program should be called in test mode
- Creates a header entry in archive management
- Includes the static archiving classes
- Opens the first archive file
- Writes the header entry in the first archive file (for example, information about the ABAP Dictionary (Nametab) tables involved)
- Dynamically include archiving classes – ARCHIVE_REGISTER_CLASS
If you want to use archiving classes, and they are to be included dynamically, you must call this function module and pass the handle for each archiving class. The function module writes the information to the archive file (for use by the succeeding programs).

Must be called directly after ARCHIVE_OPEN_FOR_WRITE.
The following steps (3 - 5) must be called in a loop for all data objects to be archived.
- Get new data object – ARCHIVE_NEW_OBJECT
You call this function module for each data object. Only then can you pass data to archiving object function modules. The function module performs the following tasks:

If you have saved a data object in the archive file using function module ARCHIVE_SAVE_OBJECT and you want to archive additional data, you must call this function module again.
- Build the data object
Call either the standard class function module ARCHIVE_PUT_RECORD or archiving class function modules. These are subject to a naming convention, in which "class" represents the archiving class name: class_ARCHIVE_OBJECT.
You must decide whether the data passed should be deleted by the delete program or not. The archiving class function modules provide the parameter OBJECT_DELETE_FLAG for this purpose.
The function module ARCHIVE_PUT_RECORD provides you with this function through the parameter RECORDS_FLAGS.
The archiving class function modules select the data for you and optimize database access. First they collect the requests and only then access the database when the function module ARCHIVE_SAVE_OBJECT is called. These function modules recognize the data object to which the data belongs through the handle that must be passed to the function module interfaces.

If you have already passed data you do not actually want to archive, call function module ARCHIVE_NEW_OBJECT. The system then discards the passed standard class and archiving class data.
- Store data object in archive file – ARCHIVE_SAVE_OBJECT
You must call the function module ARCHIVE_SAVE_OBJECT to request the actual archiving of a data object. It performs the following tasks:
- Gets the archiving class data packets
- Compresses the standard class data
- Collects the statistics data
- Updates the archive management records
- Writes the data object to the archive file (from the data container in which the records were stored by the archiving classes and the standard class)
- Closes the archive file when it reaches the specified maximum size or contains the specified maximum number of objects, and opens a new one
- Calls the delete program after an archive file has been closed
- Locks the data container, so that no more data can be written to the data container after a data object has been written to the archive file.
End of the loop (step 5.)
End archiving I – ARCHIVE_WRITE_STATISTICS
You use this function module to generate statistics about the archived data at the end of archiving. Data records passed by the standard classes (ARCHIVE_PUT_RECORD) are listed individually.
End archiving II – ARCHIVE_CLOSE_FILE
You end archiving by calling this function module. The handle passed becomes invalid and can no longer be used.

This call must not be forgotten, otherwise the last (physical) archive file to be processed is lost, and archiving is incomplete. The function module does the following:
- Updates the archive management records
- Closes the current archive file
- Releases the included archiving classes
- Discards the current handle
- Calls the delete program for the archive (if automatic deletion is specified)