Sunteți pe pagina 1din 24

White Paper

Data Archiving and


Archive Development Kit
Data Archiving and Archive Development Kit

© Copyright 2000 by SAP AG. All rights reserved.

No part of this brochure may be reproduced or transmitted in any form or for any purpose
without the express permission of SAP AG. The information contained herein may be changed
without prior notice.

Some software products marketed by SAP AG and its distributors contain proprietary software
components of other software vendors.

Microsoft®, WINDOWS®, NT®, EXCEL®, Word® and SQL-Server® are registered trademarks of
Microsoft Corporation.

IBM®, DB2®, OS/2®, DB2/6000®, Parallel Sysplex®, MVS/ESA®, RS/6000®, AIX®, S/390®,
AS/400®, OS/390®, und OS/400® are registered trademarks of IBM Corporation.

OSF/Motif® is a registered trademark of Open Software Foundation.

ORACLE® is a registered trademark of ORACLE Corporation, California, USA.

INFORMIX®-OnLine for SAP is a registered trademark of Informix Software Incorporated.

UNIX®, X/Open®, OSF/1® and Motif® are registered trademarks of the Open Group.

ADABAS® is a registered trademark of Software AG.

SAP, the SAP logo, mySAP.com, R/2, R/3, RIVA, ABAP, SAP-EDI, SAP Business Workflow, SAP
EarlyWatch, SAP ArchiveLink, ALE/WEB, BAPI, SAPPHIRE, Management Cockpit, SEM, are
trademarks or registered trademarks of SAP AG in Germany and in several other countries all
over the world. All other products mentioned are trademarks of their respective companies.

Design: SAP Communications Media

2
Data Archiving and Archive Development Kit

Contents
Introduction to Data Archiving 4

Reasons for Data Archiving 5

Data Archiving in SAP Systems 5


Archiving Object 5
Archive Administration 7
Archive Development Kit (ADK) 8
Structure of an Archiving Program 9
Structure of a Delete Program 10
Structure of a Read Program 11
Archiving Function Modules 12

Sample Archiving Program 14

Sample Delete Program 16

Sample Read Program 20

3
Data Archiving and Archive Development Kit

Introduction to Data Archiving Comprehensive checks at the application level guaran-


tee that data archiving is consistent and complete, and
When you implement business application software, that only data from completed business processes is ar-
data archiving has to be taken into account from the chived. You select the business objects to be archived,
onset. As the amount of transaction and master data can such as accounting and material documents, production
expand rapidly during production operation, you have orders, or billing documents; these objects are stored in
to consider how to control data growth. Data often archive files that can be read at a later date if required.
grows faster than technology can handle (in terms of To protect your data, only data that has been successfully
certain database limits, hard disk size, tape size, and so read from an archive file can be deleted from the data-
on). SAP Data Archiving gives you all you need to keep base.
the size of the database under control while also ensur-
The following graph shows an estimate of the archived
ing that data can be accessed in the long term; data no
data volume over a period of ten years, as well as the
longer required for daily operations or accessed less fre-
projected increase in data in the database:
quently is moved from the database to archive files.
Note, data archiving should be a periodic process,
planned and scheduled on a regular basis.

Graphic 1: Database Data Volume Versus Archive Data Volume

For data archiving, SAP provides:


■ The Archive Development Kit (ADK), an execution
and development environment, ensuring archiving is
independent of hardware and release changes.
■ Archive administration functions (transaction SARA)
■ Application data archiving solutions
■ SAP Archive Information System (SAP AS) for access-
ing archive
This paper focuses on the first two points.

4
Data Archiving and Archive Development Kit

Reasons for Data Archiving The archiving object includes:


■ Definition of logical data units in business processes
Archiving data means: ■ All programs required for archiving (preprocessing,
■ Better performance read, write, and delete programs)
◆ Faster backup and recovery ■ Definition of required Customizing
◆ Faster release upgrades In addition, programs for creating and removing an in-
◆ Faster local currency changeover (euro) dex, and for scheduling both preparation programs and
■ Efficient use of resources, for example postprocessing programs may also be included.
◆ Reduced hardware costs (fewer hard disks needed)
The data archiving solution developer uses transaction
◆ Reduced administration costs
AOBJ to define archiving objects and Customize their
■ Shorter response times in business transactions
settings.

Data Archiving in SAP Systems


Archiving Object

Graphic 2: Archiving Object

The R/3 archiving concept is based on the use of archiv-


ing objects. An archiving object is a logical unit that
describes which database objects must be combined to
obtain a complete business object.

5
Data Archiving and Archive Development Kit

The Archiving Process tween the database and the archive file. If an error oc-
Data archiving allows you to archive data in parallel to curs, you can restart the archiving process because the
normal R/3 operations. The archiving programs are data is still either in the database or in an archive file.
scheduled as background jobs and can run during pro- Graphic 3 gives an overview of the archiving process:
duction (online) operation. Data objects such as financial documents are grouped
You do not have to backup the database before you start together and written to the archive files.
the archiving process. However, we recommend you For permanent storage, you can automatically or manu-
backup the archive files. ally store the archive files in an external storage system
Data archiving consists of two basic steps: using SAP ArchiveLink or the Content Management
Service (CMS). Alternatively, you can use Hierarchical
■ Generating archive files:
Storage Management (HSM), redundant array of inde-
The archiving program writes the selected data from
pendent disks (RAID) system, or a tertiary storage sys-
the database to archive files in a magnetic file system
tem, such as a tape system.
(hard disk).
■ Deleting the data: As of Release 4.6C, you have the following choices when
The delete program first reads the data from the ar- moving the archive files to permanent storage:
chive file and then deletes the corresponding data in ■ Store after deleting
the database. After the data is written to the archive file, the data is
This two-phase process guarantees data protection if deleted from the database. Then, the archive file is
problems occur during the archiving process. For exam- moved to the storage system and deleted from the file
ple, the procedure traps network data transfer errors be- system. Choose this option for higher performance.

Grafic 3: Archiving Process

6
Data Archiving and Archive Development Kit

■ Store before deleting Within the data archiving environment, there are also
After the data is written to the archive file, the archive the following functions:
file is moved to the storage system. After this is com- ■ Tables/archiving objects
pleted, the data is read from the archive file to deter- Display the relationships between database tables and
mine which data is to be deleted from the database. archiving objects as well as display space statistics
Choose this option for increased data security. ■ Archive information system (SAP AS)
A third option offers a balance between good perform- Access individual data objects in the archive file
ance and data security: ■ Customizing
After the data is archived, the archive file is stored in Maintain the object-specific and cross-object data
the storage system, but the archive file is not deleted archiving parameters as well as file names and paths
from the file system. Then, the data is read from the ■ Job overview
archive file in the file system to determine which data Display archiving jobs
is to be deleted from the database. ■ Data archiving monitor
Monitor and analyze information about writing of
To increase data security during archiving even further,
archive files (write jobs) and deletion of data from the
verification information can be written to the archive
database (delete jobs) during an archiving session.
files along with the data. The system uses this verifica-
tion information to check archive files during delete,
read, and reload sessions. This allows the system to rec-
ognize corrupt files in time and notify the user. For ex-
ample, no delete operation at all is executed in the data-
base for a corrupt archive file.

Archive management provides three types of access to


archived data:
■ Read access to a single data object, such as a posting
document
■ Analysis of archive files via sequential read
■ Reload into the database (should be avoided whenever
possible)
For some archiving objects, retrieval of archived data is
limited to major reports and views. As part of an archiv-
ing project, you must not only determine your access
requirements for archived data but the residence times as
well.

Archive Administration
Archive administration (transaction SARA) is the central
starting point for all data archiving activities.

From here you can:


■ Schedule archiving and delete jobs
■ Read and analyze archive files
■ Build or rebuild an archive file index
■ Store and retrieve archive files
■ Reload archive files
■ Administer archiving sessions
■ Check the status of archiving sessions and files

7
Data Archiving and Archive Development Kit

Archive Development Kit (ADK) storage formats. This is only done temporarily during
read access. The data in the archive file is not changed.
Archive management is based on the Archive Develop-
ment Kit (ADK), a software layer between SAP applica- The following items are changed (if necessary) during an
tions and an archive that encapsulates the technical online conversion:
aspects of data archiving programs. This means that ar- ■ Database table structure (new and deleted columns)
chiving programs do not need to deal with file manage- ■ Data type of a column
ment or job scheduling. ADK provides an application ■ Column length
programming interface, also used by SAP developers, ■ File encoding (ASCII, EBCDIC, or specific code pag-
that customers and partners can use for the development es)
of new archiving solutions. ■ Number format (such as the use of the integer format
on various hardware platforms)
The ADK provides the functions necessary for data ar-
chiving. It supports the development of archiving and If database structures have changed more than the ADK
delete programs, as well as read and analysis programs. can handle, for example, fields have been moved from
Graphic 4 clarifies the concept of ADK and archive man- one table to another or a table has been divided into sev-
agement in the context of the SAP System. eral others, the application will take care of these chang-
es, or will provide a program for the permanent conver-
When archived data is read, the system automatically sion of existing archive files.
makes the required conversions due to any hardware and
software changes. When archived files from Release 2.1 on During archiving, data is automatically compressed by
are accessed, ADK takes database structural changes into up to a factor of five. However, if the data to be archived
account. ADK also handles different hardware-dependent is stored in cluster tables, it is not further compressed.

Graphic 4: Physical View of ADK Tool Within SAP System

8
Data Archiving and Archive Development Kit

Data Flow
Structure of an Archiving Program

Archiving Program

9
Data Archiving and Archive Development Kit

Structure of a Delete Program

Data Flow

Delete Program

10
Data Archiving and Archive Development Kit

Structure of a Read Program

Data Flow

Read Program

11
Data Archiving and Archive Development Kit

data container. This call is a prerequisite for function


module ARCHIVE_GET_NEXT_RECORD, ARCHIVE_GET_
FIRST_RECORD, and the archiving classes calls.

Archiving Function Modules ARCHIVE_GET_NEXT_RECORD


All of the following ADK function modules belong to This function module sequentially reads the next record
function group ARCH. of a data object determined by ARCHIVE_GET_NEXT_
OBJECT. The first call automatically reads the first record
ARCHIVE_CLOSE_FILE from the data container.
This function module closes all archive files that belong
ARCHIVE_NEW_OBJECT
to one handle, regardless of whether they were opened
for reading, writing, deleting, or reloading. This function module prepares a new data object to be
written to an archive, that is, it requests a new data con-
ARCHIVE_DELETE_OBJECT_DATA tainer for a handle. There can only be one current data
This function module calls the delete routines of the ar- object per handle. When calling this function module all
chive classes for the current data object. Archive classes data of the current data object is discarded and all corre-
are used to group sub-objects, such as long texts or sponding archiving classes are informed that all succeed-
change documents. ing operations for the handle belong to a new data ob-
ject. Because it may be necessary to undo any changes
ARCHIVE_GET_CUSTOMIZING_DATA to the data object, it is not checked whether the current
This function module delivers values from archiving data object was saved using function module ARCHIVE_
object Customizing, for example, the Commit. The Com- SAVE_OBJECT.
mit counter determines after how many data objects a
ARCHIVE_OPEN_FOR_DELETE
COMMIT WORK is issued.
This function module opens archives in order to delete
ARCHIVE_GET_INFORMATION their data in the database. In a running delete program
This function module returns current information for a (job) only one archive file is processed for a handle cre-
handle, such as date, release, SAP System, and archive ated by ARCHIVE_OPEN_FOR_DELETE. The status of the
name. archive files is adjusted correspondingly in archive ad-
ministration.
ARCHIVE_GET_NEXT_OBJECT
ARCHIVE_OPEN_FOR_MOVE
This function module reads the next data object for a
handle, from an archive open for reading into the ADK This function module opens archives for reloading ar-
chived data into the database. You receive a handle for
the archive files to be read and another handle for writ-
ing those data objects that are not to be reloaded. This
facilitates the selective reloading of individual data ob-
jects from archives into the SAP System while saving the
remaining data objects in a new archiving session.

ARCHIVE_OPEN_FOR_READ
This function module opens archives for reading. A han-
dle is created, through which an archive file can be read.
You can also open several archive files at the same time;
they all share one handle. Function modules that read
using this handle treat all the files for this handle as a

12
Data Archiving and Archive Development Kit

single file. Every call of the function module generates tion module, not by the ABAP statement ROLLBACK
a new handle. This enables simultaneous processing of WORK. This function module guarantees the correct re-
several archives (even from different archiving objects. setting of the data for all archiving classes used.

ARCHIVE_OPEN_FOR_WRITE ARCHIVE_SAVE_OBJECT
This function module creates a new archive file and a This function module writes a data object into an archive
handle with which you have write access to this file. file. The data passed by ARCHIVE_PUT_RECORD, as well
as the data passed via the archiving classes, is saved.
If you have not specified a logical file name in archive
Customizing, the platform-independent logical file name If the data object no longer fits in the current archive file,
ARCHIVE_DATA_FILE is automatically used to deter- the file is closed and a new archive file is automatically
mine a platform-dependent physical file name. opened. The delete program is also called automatically
if requested by the Customizing setting.
You can also specify, with control parameters, whether
the delete program for the archived data should be called ARCHIVE_WRITE_STATISTICS
automatically after writing.
This function module creates a statistics print-out for the
ARCHIVE_PUT_RECORD data objects you have written to the archive files with
ARCHIVE_SAVE_OBJECT.
This function module passes data records to the data
container previously requested by function module
ARCHIVE_NEW_OBJECT. All records you transfer to the
data container are written to the archive file when func-
tion module ARCHIVE_SAVE_OBJECT is called.

ARCHIVE_READ_OBJECT
For an archiving object, this function module reads a
particular data object from an archive file (”random ac-
cess”) and returns a handle for further processing. If a
data object was read from an archive, you can access the
data records using function modules ARCHIVE_GET_
NEXT_RECORD or ARCHIVE_GET_NEXT_STRCT_SPECIF.

ARCHIVE_RELOAD_OBJECT_DATA
This function module calls the reload routines of the ar-
chiving classes registered for the archiving object.

ARCHIVE_ROLLBACK_WORK
If a ROLLBACK WORK has to be carried out in a delete
or reload program, it must be done by calling this func-

13
Data Archiving and Archive Development Kit

Sample Archiving Program

REPORT SBOOKA.

****************************************************************************
* This is an example of how to use the ADK function modules. *
* This demo ARCHIVING program is part of the archiving object *
* BC_SBOOK. It creates a new archive session based on the data model *
* BC_TRAVEL. Actually, it only archives the database table SBOOK. *
* For production use, you have to include proper exception handling. *
****************************************************************************

* data declaration
TABLES: sbook.
DATA: button(1) TYPE c,
create(1) TYPE c VALUE ‘X’,
no_delete(1) TYPE c VALUE ‘X’,
handle LIKE sy-tabix,
sbook_itab TYPE TABLE OF sbook WITH HEADER LINE,
data_object_id LIKE arch_idx_s-obj_id.

* selection criteria and parameters


SELECTION-SCREEN BEGIN OF BLOCK arch_booking WITH FRAME TITLE text-101.
SELECT-OPTIONS: o_carrid FOR sbook-carrid
DEFAULT ‘LH ‘,
o_order FOR sbook-order_date
DEFAULT ‘19000101’ TO ‘20020101’.
SELECTION-SCREEN END OF BLOCK arch_booking.

SELECTION-SCREEN BEGIN OF BLOCK arch_control WITH FRAME TITLE text-102.


PARAMETERS: no_file LIKE button RADIOBUTTON GROUP radi,
del_test LIKE button RADIOBUTTON GROUP radi DEFAULT ‘X’,
del_prod LIKE button RADIOBUTTON GROUP radi.
SELECTION-SCREEN END OF BLOCK arch_control.

PARAMETERS comments TYPE admi_text LOWER CASE


DEFAULT ‘This is test data for archiving with BC_SBOOK’(103).

* select data from the database


SELECT * FROM sbook INTO TABLE sbook_itab
WHERE carrid IN o_carrid AND
order_date IN o_order.

* build ADK parameters from chosen button


IF no_file = ‘X’. create = ‘ ‘. no_delete = ‘ ‘. ENDIF.
IF del_test = ‘X’. create = ‘X’. no_delete = ‘X’. ENDIF.
IF del_prod = ‘X’. create = ‘X’. no_delete = ‘ ‘. ENDIF.

14
Data Archiving and Archive Development Kit

* open a new archive session to archive data


CALL FUNCTION ‘ARCHIVE_OPEN_FOR_WRITE’
EXPORTING
call_delete_job_in_test_mode = no_delete
comments = comments
create_archive_file = create
object = ‘BC_SBOOK’
IMPORTING
archive_handle = handle.

LOOP AT sbook_itab.
CONCATENATE sy-mandt sbook_itab-carrid sbook_itab-bookid
INTO data_object_id.

* initialize a new data object


CALL FUNCTION ‘ARCHIVE_NEW_OBJECT’
EXPORTING
archive_handle = handle
object_id = data_object_id. “ optional: ADK index

* put data records into ADK’s data container


CALL FUNCTION ‘ARCHIVE_PUT_RECORD’
EXPORTING
archive_handle = handle
record_structure = ‘SBOOK’
record = sbook_itab.

* further (depending) records from other tables usually follow


*
* loop at <depending table X> where ...
* call function ‘ARCHIVE_PUT_RECORD’ ...
* endloop.
* loop at <depending table Y> where ...
* call function ‘ARCHIVE_PUT_RECORD ...
* endloop.

* write data object into the archive file


CALL FUNCTION ‘ARCHIVE_SAVE_OBJECT’
EXPORTING
archive_handle = handle.
ENDLOOP.
* create the default spool list
CALL FUNCTION ‘ARCHIVE_WRITE_STATISTICS’
EXPORTING
archive_handle = handle.

* close the archive session


CALL FUNCTION ‘ARCHIVE_CLOSE_FILE’
EXPORTING
archive_handle = handle.

15
Data Archiving and Archive Development Kit

Sample Delete Program

REPORT sbookd.

**************************************************************************
* This is an example of how to use the ADK function modules. *
* This demo DELETE program removes data from the database table SBOOK. *
* At the same time, an index can be built up to support random access. *
* The related archiving program in archiving object BC_SBOOK is SBOOKA. *
* For production use, you have to include proper exception handling. *
**************************************************************************

* data declaration
CONSTANTS:
object LIKE arch_obj-object VALUE ‘BC_SBOOK’.
DATA:
handle LIKE sy-tabix,
buffer TYPE arc_buffer,
sel_files_itab TYPE TABLE OF arch_files,
sbook_wa LIKE sbook,
sbook_itab TYPE TABLE OF sbook,
commit_cnt LIKE arch_usr-arch_comit,
object_cnt TYPE i,
arkey LIKE arch_idx_s-archivekey,
object_id LIKE arch_idx_s-obj_id,
offset LIKE arch_idx_s-obj_offset,
index_tab TYPE TABLE OF arch_idx_s WITH HEADER LINE,
index_flag LIKE arch_usr-arch_index,
sum_objects TYPE i VALUE 0,
stat_itab TYPE TABLE OF arch_stat,
tabfield LIKE arch_stat.

PARAMETERS: testrun DEFAULT ‘X’ AS CHECKBOX. “ do not delete


“ from database
* open a new archive session to delete data
CALL FUNCTION ‘ARCHIVE_OPEN_FOR_DELETE’
EXPORTING
object = object
test_mode = testrun
IMPORTING
archive_handle = handle
EXCEPTIONS
OTHERSq = 01.
IF sy-subrc <> 0.
WRITE / ‘No file can be accessed’(001).
EXIT.
ENDIF.

16
Data Archiving and Archive Development Kit

* get customizing data from the archive object


CALL FUNCTION ‘ARCHIVE_GET_CUSTOMIZING_DATA’
EXPORTING
object = object
IMPORTING
commit_count_for_delete_prg = commit_cnt
maintain_index = index_flag.

* loop to get the next data object from the archive file(s)
CLEAR object_cnt.
DO.
ADD 1 TO object_cnt.
CALL FUNCTION ‘ARCHIVE_GET_NEXT_OBJECT’
EXPORTING

archive_handle = handle
IMPORTING
object_id = object_id
object_offset = offset
archive_name = arkey
EXCEPTIONS
end_of_file = 01.
IF sy-subrc = 1.
EXIT.
ENDIF.

* build an index to allow for random access to data objects


*** This index is optional. Try to use the Archive Information
*** System SAP AS instead.

IF index_flag IS INITIAL.
* no index is to be built according to customizing
ELSEIF testrun IS INITIAL.
MOVE: object_id TO index_tab-obj_id,
arkey TO index_tab-archivekey,
offset TO index_tab-obj_offset.
APPEND index_tab.
PERFORM save_index_tab ON COMMIT.
ENDIF.

Continuation
see next page

17
Data Archiving and Archive Development Kit

Sample Delete Program (Continuation)

* loop to get data records from ADK’s data container


DO.
CALL FUNCTION ‘ARCHIVE_GET_NEXT_RECORD’
EXPORTING
archive_handle = handle
IMPORTING
record = buffer-segment
record_structure = buffer-rname
EXCEPTIONS
end_of_object = 01.
IF sy-subrc = 1.
EXIT.
ENDIF.

* keep data records in mind; take their structure into account


CASE buffer-rname.
WHEN ‘SBOOK’.
MOVE buffer-segment TO sbook_wa.
APPEND sbook_wa TO sbook_itab. “ will be deleted in db
* when ... “ further structures
ENDCASE.
ENDDO.

IF testrun IS INITIAL AND object_cnt = commit_cnt.


PERFORM delete_from_table. “ actual delete from database
CLEAR object_cnt. “ restart counting up to
ENDIF. “ value of commit counter
ENDDO.

IF testrun IS INITIAL AND object_cnt > 1.


PERFORM delete_from_table. “ deleting last package
ENDIF.

* provide statistics
tabfield-tabname = ‘ ‘.
tabfield-count = sum_objects.
APPEND tabfield TO stat_itab.
tabfield-tabname = ‘SBOOK’.
APPEND tabfield TO stat_itab.
CALL FUNCTION ‘ARCHIVE_GIVE_STATISTICS’
EXPORTING
archive_handle = handle
TABLES
table = stat_itab.

* write statistics
CALL FUNCTION ‘ARCHIVE_WRITE_STATISTICS’
EXPORTING
archive_handle = handle
statistics_only_per_file = ‘X’.

18
Data Archiving and Archive Development Kit

* get all processed files for update of index status


CALL FUNCTION ‘ARCHIVE_GET_ARCHIVE_FILES’
EXPORTING
archive_handle = handle
TABLES
archive_files = sel_files_itab.

* close the archive session


CALL FUNCTION ‘ARCHIVE_CLOSE_FILE’
EXPORTING
archive_handle = handle.

* set status “index created” in SARA administration


IF index_flag IS INITIAL.
* no index has been built according to customizing
ELSEIF testrun IS INITIAL.
CALL FUNCTION ‘ARCHIVE_ADMIN_SET_STATUS’
EXPORTING
files_are_converted = ‘ ‘
index_created = ‘X’
TABLES
archive_files = sel_files_itab.
ENDIF.

* ---------------------------------------------- *
* FORM DELETE_FROM_TABLE *
* ---------------------------------------------- *
* global: sbook_itab, sum_objects
* ---------------------------------------------- *

FORM delete_from_table.
DATA: tabcount TYPE i VALUE 0.
DELETE sbook FROM TABLE sbook_itab. “ delete job restartable
COMMIT WORK.
DESCRIBE TABLE sbook_itab LINES tabcount.
sum_objects = sum_objects + tabcount.
REFRESH sbook_itab.
ENDFORM. “ DELETE_FROM_TABLE

* ---------------------------------------------- *
* Form SAVE_INDEX_TAB *
* ---------------------------------------------- *
* global: index_tab
* ---------------------------------------------- *

FORM save_index_tab.
DELETE arch_idx_s FROM TABLE index_tab.
INSERT arch_idx_s FROM TABLE index_tab
REFRESH index_tab.
ENDFORM. “ SAVE_INDEX_TAB

19
Data Archiving and Archive Development Kit

Sample Read Program

REPORT sbookr.

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* This is an example of how to use the ADK function modules. *
* This READ program demonstrates reporting from/analyzing archives. *
* The only output is the number of records and the last record read. *
* It belongs to the archiving object BC_SBOOK based on BC_TRAVEL. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

* data declaration
DATA: handle LIKE sy-tabix,
buffer TYPE arc_buffer,
sbook_wa LIKE sbook,
number_of_records_read TYPE i.

* open existing archive files


CALL FUNCTION ‘ARCHIVE_OPEN_FOR_READ’
EXPORTING
object = ‘BC_SBOOK’
IMPORTING
archive_handle = handle
EXCEPTIONS
OTHERS = 1.

IF sy-subrc <> 0.
WRITE: / ‘No file can be accessed’(001).
EXIT.
ENDIF.

CLEAR number_of_records_read.
* loop to get the next data object from the archive file(s)
DO.
CALL FUNCTION ‘ARCHIVE_GET_NEXT_OBJECT’
EXPORTING
archive_handle = handle
EXCEPTIONS
end_of_file = 1
OTHERS = 2.
IF sy-subrc <> 0.
EXIT.
ENDIF.

20
Data Archiving and Archive Development Kit

* get data records from the data container


DO.
CALL FUNCTION ‘ARCHIVE_GET_NEXT_RECORD’
EXPORTING
archive_handle = handle
IMPORTING
record = buffer-segment
record_structure = buffer-rname
EXCEPTIONS
end_of_object = 1
OTHERS = 2.
IF sy-subrc <> 0.
EXIT.
ENDIF.

ADD 1 TO number_of_records_read.
ENDDO.
ENDDO.

WRITE: / ‘Total number of records read: ‘(002), number_of_records_read.


SKIP.
WRITE / ‘Last record read: ‘(003).
SKIP.
CASE buffer-rname.
WHEN ‘SBOOK’.
sbook_wa = buffer-segment.
WRITE: / ‘CARRID :’, sbook_wa-carrid,
/ ‘BOOKID :’, sbook_wa-bookid,
/ ‘CONNID :’, sbook_wa-connid,
/ ‘FLDATE :’, sbook_wa-fldate,
/ ‘CUSTOMID :’, sbook_wa-customid,
/ ‘ORDER_DATE:’, sbook_wa-order_date,
/ ‘...’.

* when ...
* If the archive object contained more than one table
* (different buffer-rname), more cases would be needed.
ENDCASE.

* close the archive session


CALL FUNCTION ‘ARCHIVE_CLOSE_FILE’
EXPORTING
archive_handle = handle.

21
Data Archiving and Archive Development Kit

Additional sample programs for the archiving


object ”EXAMPLE”

■ RSARCH04 (archiving program)


■ RSARCH06 (delete program)
■ RSARCH19 (read program)

22
Data Archiving and Archive Development Kit

23
SAP AG
Neurottstrasse 16
69190 Walldorf, Germany
Mailing address
69189 Walldorf, Germany
SAP information service
Tel. +49 (180) 5 34 34 24
Fax +49 (180) 5 34 34 20
www.mysap.com

www.sap.com
You can find this and other current literature on our home page in the media centers for each subject.

50 037 186S(0002/xx) Printed on environmentally friendly paper.

S-ar putea să vă placă și