You are on page 1of 3

Access Archived Data from ABAP

Its true that storage cost are so cheap. Every day we create a lot of data and would never thinking of
removing it. Its the same in SAP world, but I still believe Data Archiving is an important concept
which every client should be considered to maintain a well-performed system.
Archived Data means those obsolete data which has completed their lives and no longer needed in the
system, and has been moved out of the SAP online database using the SAP standard function Archive
Development Kit (ADK).
The normal SQL statement could not read the archived data, since they have already been moved to
the external file system. Customized programs that need to read archived data should follow one of
the below methods:
1. Use the following standard functional module to read the data directly from the file system:
ARCHIVE_OPEN_FOR_READ Open archived file for reading
ARCHIVE_GET_NEXT_OBJECT Read the next data object, e.g. a new accounting document
number, from the archive file.
ARCHIVE_GET_NEXT_RECORD Read the next record, e.g. within an accounting document,
there are several records including BKPF, BSEG, etc.
ARCHIVE_CLOSE_FILE Close archived file
For example, the following shows the process flow in a customized program:
PERFORM ARCHIVE_OPEN_FOR_READ
Loop at data object in the archive file
PERFORM ARCHIVE_GET_NEXT_OBJECT
Loop at data record in the data object.
ARCHIVE_GET_NEXT_READ
Endloop.
Endloop.
PERFORM ARCHIVE_CLOSE_FILE
Complicated? I agree that to use these functional modules requires some advanced ABAP coding
techniques. If you feel its complicated, the second method is much easier.
2. Read Information Structure Tables
The pre-requisite is to define Information Structure tables which stores the fields to be used in the
search and display of data. By activating the information structure, a physical SAP table would be
generated which could be used in customized reports for searching archived data. After that, normal
SQL statements could be used to access archived data.

Information Structure tables are defined using transaction SARI. For example, the table ZARIXFI1 are
generated to store selected archived data from BKPF. In the customized program, the following coding
are used:
SELECT * FROM BKPF INTO TABLE W_BKPF WHERE BUKRS = P_BUKRS
AND BELNR = P_BELNR.
SELECT * FROM ZARIXFI1 APPENDING TABLE W_BKPF
WHERE BUKRS = P_BUKRS
AND BELNR = P_BELNR.
3. Read Text Information
Special techniques would be needed to be used to access the TEXT data in the archived file.
Following are sample coding:
* Check whether the record exist in information structure table
select single * from zarixsd1 where vbeln = ioutput-vbeln.
if sy-subrc eq 0.
* Get the handle by calling functional module ARCHIVE_READ_OBJECT
call function ARCHIVE_READ_OBJECT
exporting
object = SD_VBAK
archivkey = zarixsd1-archivekey
offset = zarixsd1-archiveofs
importing
archive_handle = handle
exceptions
no_record_found = 1
file_io_error = 2
internal_error = 3
open_error = 4
cancelled_by_user = 5
archivelink_error = 6
object_not_found = 7
filename_creation_failure = 8
file_already_open = 9
not_authorized = 10
file_not_found = 11
others = 12
.
* Call READ_TEXT and pass handle as import parameter
call function READ_TEXT
exporting
id = t_id
language = E

name = t_name
object = t_object
archive_handle = handle
tables
lines = i_txtline
exceptions
id = 1
language = 2
name = 3
not_found = 4
object = 5
reference_check = 6
wrong_access_to_archive = 7
others = 8.

You might also like