A Developer's Guide to Archiving Custom Z-Tables
Standard SAP archiving objects are great, but what about the massive custom Z-tables your organization has created over the years? Leaving them to grow unchecked is a major DVM risk. This guide provides a technical overview for developers on how to create a custom archiving solution.
THE GOAL: CREATE A COMPLETE ARCHIVING OBJECT
The objective is to build a custom archiving object that behaves like a standard one. It should be configurable in transaction SARA and consist of programs to write, delete, and reload data based on defined business logic.
STEP 1: ANALYSIS - THE MOST CRITICAL PHASE
Before writing a single line of code, you must become an expert on the data. Answer these questions:
- Data Model: Which Z-tables are part of the business object? Are there header and item tables?
- Dependencies: Is the data linked to any standard SAP documents (e.g., a custom table that extends Sales Orders)? If so, you cannot archive the Z-table data until the standard document is archived. This is a critical point.
- Archivability Criteria: What defines a record as "archivable"? Is it based on a date, a status field, or a combination of factors? This logic must be defined and approved by the business.
STEP 2: CREATE THE ARCHIVING OBJECT (AOBJ)
Transaction AOBJ is where you define the metadata for your new object (e.g., ZMYOBJECT).
- Name and Tables: Define the object name and list all primary Z-tables that will be archived by it.
- Program Names: Assign names for the custom ABAP programs you will create (e.g.,
Z_MYOBJECT_WRITE,Z_MYOBJECT_DELETE,Z_MYOBJECT_RELOAD). - Customizing Settings: Link to the customizing transaction where users will maintain variants for your archiving jobs.
STEP 3: DEVELOP THE ABAP PROGRAMS
This is the core development work. You will create three main programs:
- The Write Program: This program selects the data that meets the archivability criteria. It uses standard Archive Development Kit (ADK) function modules like
ARCHIVE_OPEN_FOR_WRITEto create the archive file andARCHIVE_PUT_TABLEto move data into it. - The Delete Program: After the write job is complete, this program reads the newly created archive file to confirm which records were successfully archived, and then deletes those specific records from the database tables.
- The Reload Program: A best practice is to also create a program to reload archived data back into the database. This is crucial for error correction and provides a safety net during testing.
STEP 4: TESTING AND INTEGRATION IN SARA
Once the object is defined in AOBJ and the programs are developed, your object will automatically appear in transaction SARA. From here, the process is the same as for a standard object: create a variant, schedule the write job, then the delete job. Thorough testing with business user validation is essential to ensure data integrity and accessibility.
Related Reading
This guide covers the "how." For the "why," explore our Ultimate Guide to DVM in S/4HANA.
CUSTOM DEVELOPMENT CREATING DVM HEADACHES?
Building custom archiving objects requires deep technical expertise. The Sapixos development team can help you analyze, build, and deploy a robust solution for your Z-tables.
Consult Our Development Experts