Data ArchivingSAP AG Data Archiving and Archive Development Kit October 2001 Copyright 2001 SAP AG Contents Introduction to Data Archiving for mySAP Technology _____________________________________ 3 Reasons for Data Archiving__________________________________________________________ 4 Data Archiving in the mySAP.com Environment __________________________________________ 4 Archiving Object_________________________________________________________________ 4 Archiving Process _______________________________________________________________ 5 Reading Archive Files ____________________________________________________________ 6 Data Archiving Tools _____________________________________________________________ 6 Archive Development Kit (ADK)_____________________________________________________ 7 Data Archiving Statistics __________________________________________________________ 8 Developing Archiving Programs ______________________________________________________ 9 Structure of a Write Program ______________________________________________________ 10 Structure of a Delete Program _____________________________________________________ 10 Structure of a Delete Program _____________________________________________________ 11 Structure of a Read Program______________________________________________________ 11 Structure of a Read Program______________________________________________________ 12 Archiving Function Modules in Function Group ARCH ____________________________________ 13 Sample Programs ________________________________________________________________ 15 Write Program _________________________________________________________________ 15 Delete Program ________________________________________________________________ 17 Read Program _________________________________________________________________ 20 Copyright 2001 SAP AG Page 2 of 2 Introduction to Data Archiving for mySAP Technology When you implement mySAP.com e-business solutions, data archiving is an important aspect to be taken into account from the beginning. The amount of transaction and master data in your production database can expand rapidly during operation, often faster than technology can handle it (for example, database limits, hard-disk sizes, time available for backup and recovery or statistics update, and so on). With data archiving, you have everything you need to manage database size and system performance while also ensuring that data can continue to be accessed in the long term. Data from completed business operations that is no longer required for daily operations or accessed less frequently is copied from the database to archive files and then deleted from the database. To take full advantage of what data archiving has to offer, you have to plan and schedule the process on a regular basis. Comprehensive archivability checks at the application level guarantee that the data archived is consistent and complete and that only data from completed business processes is archived. You simply select the business objects to be archived, such as accounting and material documents, production orders, or billing documents. These objects are stored in archive files outside the production database and can then be read from these files at a later date if required. The following graph shows how data archiving can keep database growth under control. Note that with regular data archiving process execution even though the database continues to grow, it grows at a slower and more controlled rate. Data growth, which indicates healthy business growth, is managed and controlled: 700.00 Expected size without Archiving 600.00 500.00 400.00 300.00 'Without' Archiving 200.00 100.00 Initial Archiving With regular archiving DB growth: Reduction: ~15 GB/month ~60GB DB growth: ~7 GB/month SEP 00 AUG 00 JUL 00 JUN 00 MAY 00 APR 00 MAR 00 FEB 00 JAN 00 DEC 99 NOV 99 OCT 99 SEP 99 AUG 99 JUL 99 JUN 99 MAY 99 APR 99 MAR 99 0.00 Figure 1: Database Volume Versus Archive Volume Data Archiving for mySAP Technology provides: • The Archive Development Kit (ADK), an execution and development environment that ensures archiving is independent of hardware and release changes • Archive administration functions (transaction SARA) • Support for Unicode data • Comprehensive statistics Copyright 2001 SAP AG Page 3 of 3 • • Remote-enabled administration functions for creating your own Web applications Archive browsing using the Archive Information System (AS) This paper focuses on the first four points. Reasons for Data Archiving Archiving data and the related reduction in the volume of active online data allows: Ø Better performance • • • Ø Efficient use of resources • • Ø Faster backup and recovery Faster release upgrades Faster analysis of database statistics (if a cost-based optimizer is used) Reduced hardware costs (fewer hard disks, less CPU, and memory capacity needed) Reduced administration costs Shorter response times in transactions Data Archiving in the mySAP.com Environment Archiving Object SAP’s archiving concept is based on the use of archiving objects. An archiving object is a logical unit that describes which database objects are required to obtain a complete business object. Archiving Objects Data Customizing Programs Figure 2: Archiving Object Copyright 2001 SAP AG Page 4 of 4 The archiving object includes: § A definition of the logical data units in business processes § All programs required for archiving, for example preprocessing, write, delete, and read programs § Customizing settings Optional programs for creating and deleting an ADK index and for postprocessing may also be included. The data archiving solution developer uses transaction AOBJ to define archiving objects and customize the settings. Archiving Process You can archive data simultaneously with normal online operations. You schedule the archiving programs as background jobs in transaction SARA and do not have to backup the database before you start the archiving process. However, we strongly recommend you backup the archive files after archiving. The data archiving process consists of two basic steps and an optional third step. This two-step process guarantees data protection if problems occur during the archiving process; for an overview, see figure 3. Business Transactions/ Reporting Read Archived Files Database Application Data Data Objects Archive Files Write to Archive Files Delete from Database Figure 3: Overview of the Data Archiving Process • Step1: Write Phase The write program reads the selected data from the database and writes it to archive files. During archiving, data is automatically compressed on average by a factor of five. However, if the data to be archived is stored in cluster tables, it is not compressed any further. • Step 2: Delete Phase Copyright 2001 SAP AG Page 5 of 5 The delete program reads the data from the archive files and, if the archive file is successfully read (that is the archive file is intact), deletes the corresponding data in the database. The delete program only deletes data from the database that has been successfully read from an archive file. If an error occurs, such as a data transfer error, you can restart the archiving process because the data is still either in the database or in an archive file. To increase data security during archiving even further, verification information can be written to the archive files along with the data. The system uses this verification information to check archive files during delete, read, and reload sessions. This allows the system to recognize corrupt files in time and notify the user. For example, no delete operation is executed in the database for a corrupt archive file. • Optional Step 3: Storage Phase You can manually or automatically move the archive files to an external storage system using ArchiveLink or the Content Management Infrastructure. Alternatively, you can use a Hierarchical Storage Management (HSM) system, redundant array of independent disks (RAID) system, or a tertiary storage system, such as a tape system. As of SAP R/3 4.6C, you can specify when to move the archive files to permanent storage: § Delete Before Storing (higher performance) After the data is written to the archive file, the data is deleted from the database as described above. Then, the archive file is moved to the external storage system and removed from the file system. § Store Before Deleting (increased data security) After the data is written to the archive file, the archive file is stored in the storage system and then deleted from the file system. After this is completed, the data is read from the storage system to determine which data is to be deleted from the database. § Third option: combines good performance and data security After the data is archived, the archive file is moved to the external storage system, but the archive file is not yet removed from the file system. Then, the data is read from the archive file in the file system to determine which data is to be deleted from the database. Finally, the archive file is removed from the file system. Reading Archive Files Once the archive files are written, you have two types of access to the archived data: • Read access to a single data object, such as a posting document • Analysis of archive files via sequential read Data Archiving Tools The most essential tools are available in the Data Archiving Administrator user role in SAP Basis 4.6C/4.6D and from SAP Web Application Server (SAP Web AS) 6.10. Archive Administration (transaction SARA) is the central starting point for all data archiving activities. From here you can: • Schedule write and delete jobs Copyright 2001 SAP AG Page 6 of 6 • • • • • • • Interrupt and continue archiving sessions (new in SAP Web AS 6.10) Manage archiving sessions and check the status of both archiving sessions and archive files Display detailed data archiving statistics (new in SAP Web AS 6.10) Store and retrieve archive files Read archive files Build or delete an archive file index Reload archiving sessions The following related functions are also available in transaction SARA: • Tables and Archiving Objects Determine which tables are contained in an archiving object and which archiving objects access specific tables; display space statistics (the statistics functions vary depending on the database used) • Archive Information System (AS) Access individual documents in the archive file • Customizing Maintain the archiving-object-specific and cross-archiving-object parameters as well as file names and paths • Job Overview Display archiving jobs • Network Graphic Display recommended order for sequencing of archiving objects; for more information, see SAP Note 391350 • Archive Information System (choose Information System or use transaction SARI) Allows you to read archive files and display data using archive information structures you define and fill. For more information, see the SAP Library → Cross-Application Components → Application Data Archiving → Introduction to Data Archiving → Archive Information System. Other useful tools: • Data Archiving Monitor: also available in the alert monitor (transaction RZ20) Monitor and analyze information about writing of archive files (write jobs) and deletion of data from the database (delete jobs) during an archiving session. • RFC administration function modules in function group ARCXDA Function modules that allow you to schedule archiving jobs, and interrupt and continue archiving sessions • Document Relationship Browser (access through AS or use transaction ALO1) Analyze and display links across applications to and from documents and other objects that are stored in the archive or in the active database Archive Development Kit (ADK) Data Archiving for mySAP Technology is based on the Archive Development Kit (ADK), a service of mySAP Technology. ADK is a software layer between mySAP.com components, the database, and an archive. In archiving programs, it separates the technical aspects from the application logic. This means that archiving programs do not need to deal with file management or job scheduling. ADK provides an application programming interface (API), also used by SAP, that customers and partners can use for developing their own archiving solutions. This API includes all the functions needed for developing archiving programs, including write, delete, and read programs. With SAP Web Application Server 6.10, ADK supports the archiving of Unicode data. The following figure clarifies the concept of ADK and archive management in the context of mySAP.com: Copyright 2001 SAP AG Page 7 of 7 mySAP.com Legend Data Flow Archive Administration Control Flow File System Archiving program Archiving for program Writeobject A for object Program A Archive Files for Object XYZ Archive Development Kit (ADK) Database Application Data ArchiveLink and Content Management Infrastructure Tape Hierarchical Storage Management (HSM) Administration Data Storage System Figure 4: Physical View of ADK Tool Within the mySAP.com Environment ADK also automatically makes the required conversions due to any hardware and software changes when archived data is read. When archived files from SAP R/3 3.0 on are accessed, ADK takes database structural changes into account. ADK also handles different hardware-dependent storage formats. This is only done temporarily during read access and does not change the data in the archive file. The following items are changed (if necessary) during an online conversion: • Database table structure: new and deleted columns • Data type of a column • Column length • Character encoding (ASCII, EBCDIC, or specific code pages) • Number format (such as the use of the integer format on various hardware platforms) If database structures have changed more than ADK can handle, for example, fields have been moved from one table to another or a table has been divided into several others, the application will usually take care of these changes. If not, the application will provide a program you can use to permanently convert existing archive files for standard SAP archiving objects. Data Archiving Statistics From SAP Web AS 6.10, new comprehensive data archiving statistics include information about duration of archiving sessions, amount of space freed by archiving, amount of space used by archive files, and more. This information helps the data archiving administrator: • Show the results of data archiving Copyright 2001 SAP AG Page 8 of 8 • • • Demonstrate the effectiveness of data archiving Better plan data archiving projects Recognize bottlenecks in time From SAP Web AS 6.10, data archiving statistics are stored permanently and can be displayed as needed using the Statistics function in transaction SARA. How Is the Database Information Calculated? In write programs, ADK automatically collects statistics. In delete, read, and reload programs, you must use ARCHIVE_GIVE_STATISTICS to pass statistical information to ADK. The statistics collected by ARCHIVE_GIVE_STATISTICS can be displayed from transaction SARA. ARCHIVE_GIVE_STATISTICS can accept data for any of the six ABAP Dictionary object types: • TRANSP: transparent table • POOL: pooled table • VIEW: database or projection view • CLUSTER: cluster table • INTTAB: structure, help view, maintenance view, or structure view • APPEND: append structure ADK uses the function module DDIF_TABL_GET to get the width of the relevant table or index. The statistics are then calculated by multiplying the number of records by the returned ABAP Dictionary width. After calculating the database space, ADK assigns each result to one of four database space categories (DB Table Space, DB Index Space, DB Cluster Space, and DB Structure Space) . These correspond to the categories in the Statistics function in Archive Administration. DB Space is the sum of these four categories. Developing Archiving Programs In the following section, we describe the structure of write, delete, and read programs. This includes diagrams of program data flow and structure, including the location of the loop(s). To understand these programs requires definitions of two terms. Data container: The buffer in which the various table entries for a logical business object are collected during a program run, before they are written as a complete data object to the archive file. Archive handle: A temporary identifier to group the data objects and related archive files processed by the ADK function modules in a set order in a program. Copyright 2001 SAP AG Page 9 of 9 Structure of a Write Program Data Flow ADK Definition of Archiving Object XYZ Database A Table B Table C Table Select Data 1 ARCHIVE_OPEN_FOR_WRITE ABAP Program with Internal Tables 2 ARCHIVE_NEW_OBJECT Request Data Container 3 A ARCHIVE_PUT_RECORD _________ Write Data Record _________ to Data Container 3 B ARCHIVE_PUT_RECORD _________ _________ 3 C ARCHIVE_PUT_RECORD _________ _________ Data Container with Current Data Object A B B B 4 ARCHIVE_SAVE _OBJECT B Write Data Object to Archive File Archive File C C C 5 ARCHIVE_CLOSE_FILE Structure Declaration part DATABASE TABLES (tabA, tabB, tabC) INTERNAL TABLES (itabA, itabB, itabC) PARAMETERS Select data from database SELECT * FROM tab INTO itab Open a new archiving session ARCHIVE_OPEN_FOR_WRITE Loop (n = number of data objects/records in header table) LOOP n TIMES Initialize data container ARCHIVE_NEW_OBJECT Put data records from itabA into data container ARCHIVE_PUT_RECORD Loop (m = number of records in itabB) LOOP m TIMES Put data records from itabB into data container ARCHIVE_PUT_RECORD ENDLOOP Loop (p = number of records in itabC) LOOP p TIMES Put data records from itabC into data container ARCHIVE_PUT_RECORD ENDLOOP Write data objects to archive file ARCHIVE_SAVE_OBJECT ENDLOOP Create statistics ARCHIVE_WRITE_STATISTICS Close archiving session CopyrightARCHIVE_CLOSE_FILE 2001 SAP AG Page 10 of 10 Structure of a Delete Program Data Flow Database ADK Definition of Archiving Object XYZ A Table B Table C Table Delete Data ABAP Program with Internal Tables 1 ARCHIVE_OPEN_FOR_DELETE Data Container with 3 Current Data Object ARCHIVE_GET_NEXT_RECORD A __ _ _ _ _ _ _ _ Read Data Record __ _ _ _ _ _ _ _ from Data Container A 3 ARCHIVE_GET_NEXT_RECORD __ _ _ _ _ _ _ _ __ _ _ _ _ _ _ _ B 3 ARCHIVE_GET_NEXT_RECORD __ _ _ _ _ _ _ _ __ _ _ _ _ _ _ _ C B C 2 ARCHIVE_GET_NEXT _OBJECT B B Read Data Object from Archive File Archive File B C C 4 ARCHIVE_CLOSE_FILE Structure Declaration part DATABASE TABLES (tabA, tabB, tabC) INTERNAL TABLES (itabA, itabB, itabC) PARAMETERS Open a new archiving session to delete data ARCHIVE_OPEN_FOR_DELETE Get the commit counter belonging to the archive object ARCHIVE_GET_CUSTOMIZING_DATA Loop (n = number of data objects in archive file) LOOP n TIMES Get next object from the archive files into data container ARCHIVE_GET_NEXT_OBJECT Loop (r = number of records in data container) LOOP r TIMES Get next data records from data container into ABAP report ARCHIVE_GET_NEXT_RECORD or ARCHIVE_GET_TABLE (better) ENDLOOP Delete data (array delete according to commit counter) DELETE tab FROM itab ARCHIVE_GIVE_STATISTICS ENDLOOP Close the archiving session ARCHIVE_CLOSE_FILE Copyright 2001 SAP AG Page 11 of 11 Structure of a Read Program Data Flow ADK Definition of Archiving Object XYZ A Table B Table C Table Read Data ABAP Program with Internal Tables 1 ARCHIVE_OPEN_FOR_READ Data Container 3 With Current ARCHIVE_GET_NEXT_RECORD Data Object A __ _ _ _ _ _ _ _ Read Data Record __ _ _ _ _ _ _ _ from Data Container 2 B ARCHIVE_GET_NEXT _OBJECT 3 B ARCHIVE_GET_NEXT_RECORD B Archive File Read Data Object __ _ _ _ _ _ _ _ B from Archive file __ _ _ _ _ _ _ _ B A 3 C ARCHIVE_GET_NEXT_RECORD C __ _ _ _ _ _ _ _ __ _ _ _ _ _ _ _ C C 4 ARCHIVE_CLOSE_FILE Structure Declaration part DATABASE TABLES (tabA, tabB, tabC) INTERNAL TABLES (itabA, itabB, itabC) PARAMETERS Open a new archiving session to delete data ARCHIVE_OPEN_FOR_READ Loop (n = number of data objects in archive file) LOOP n TIMES Get next object from the archive files into data container ARCHIVE_GET_NEXT_OBJECT Loop (r = number of records in data container) LOOP r TIMES Get next data records from data container into ABAP report ARCHIVE_GET_NEXT_RECORD ENDLOOP Read data WRITE ... ENDLOOP Close the archiving session ARCHIVE_CLOSE_FILE Copyright 2001 SAP AG Page 12 of 12 Archiving Function Modules in Function Group ARCH This list is not a complete list of all archiving function modules. It only reflects those function modules mentioned in this white paper. For information about all the function modules, see the online function module documentation. ARCHIVE_CLOSE_FILE This function module closes all archive files that belong to one handle, independently of whether they were opened for reading, writing, deleting, or reloading. ARCHIVE_GET_CUSTOMIZING_DATA This function module delivers values from archiving object Customizing, for example, the commit counter, which determines after how many data objects a COMMIT WORK is issued. ARCHIVE_GET_NEXT_OBJECT This function module reads the next data object for an archive handle into the ADK data container from an archive open for reading or deleting. This call is a prerequisite for function module ARCHIVE_GET_NEXT_RECORD and ARCHIVE_GET_TABLE. ARCHIVE_GET_NEXT_RECORD This function module sequentially reads the next record of a data object determined by ARCHIVE_GET_NEXT_OBJECT. The first call automatically reads the first record from the data container. ARCHIVE_GIVE_STATISTICS This function module is used to pass statistical data to ADK and must be used in delete programs, but must not be used in write programs. ARCHIVE_NEW_OBJECT This function module prepares a new data object to be written to an archive, that is, it requests a new data container for an archive handle. There can only be one current data object per handle. When calling this function module all data of the current data object is discarded. Because it may be necessary to undo any changes to the data object, ADK does not check whether the current data object was saved using function module ARCHIVE_SAVE_OBJECT. ARCHIVE_OPEN_FOR_DELETE This function module opens archives in order to delete their data from the database. Each delete job processes one archive file for an archive handle created by ARCHIVE_OPEN_FOR_DELETE. The status of the archive files is adjusted accordingly in archive management. ARCHIVE_OPEN_FOR_READ This function module opens archives for reading. An archive handle 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 archive handle. Function modules that read using this archive handle treat all the files for this archive handle as a single file. Every call of the function module generates a new archive handle. This enables the simultaneous processing of several archives (even from different archiving objects). Copyright 2001 SAP AG Page 13 of 13 ARCHIVE_OPEN_FOR_WRITE This function module creates a new archive file and an archive handle with which you have write access to this file. If you have not specified a logical file name in Customizing, the platform-independent logical file name ARCHIVE_DATA_FILE is automatically used to determine a platform-dependent physical file name. You can use control parameters to specify whether the delete program for the archived data should be called automatically after writing. ARCHIVE_PUT_RECORD This function module passes data records to the data container that was previously requested by function module ARCHIVE_NEW_OBJECT. All records you transfer to the data container are written to the archive file when function module ARCHIVE_SAVE_OBJECT is called. 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 function module, not by the ABAP statement ROLLBACK WORK. ARCHIVE_SAVE_OBJECT This function module writes a data object to an archive file. The data passed by ARCHIVE_PUT_RECORD is saved. If the data object no longer fits in the current archive file, the file is closed and a new archive file is automatically opened. The delete program is also called automatically if requested by the Customizing setting. ARCHIVE_WRITE_STATISTICS This function module creates a statistics print-out for the data objects you have written to the archive files with ARCHIVE_SAVE_OBJECT. Copyright 2001 SAP AG Page 14 of 14 Sample Programs Write Program For an additional example of a write program, see the RSARCH04 program. ******************************************************************************************** * This is an example of how to use the ADK function modules. * * This demo WRITE program is part of the archiving object called * * BC_SBOOK. It creates a new archiving session based on the data model * * BC_TRAVEL. Actually, only the database table SBOOK is archived. * * For production use, you have to include proper exception handling. * ******************************************************************************************** REPORT sbooka. * 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, session_interrupted TYPE c VALUE ' '. * 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. * open a new archiving 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' Copyright 2001 SAP AG Page 15 of 15 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. * (or preferrable: call function 'ARCHIVE_PUT_TABLE'...) * write data object into the archive file CALL FUNCTION 'ARCHIVE_SAVE_OBJECT' EXPORTING archive_handle = handle EXCEPTIONS termination_requested = 1. IF sy-subrc = 1. session_interrupted = 'X'. EXIT. ENDIF. ENDLOOP. IF session_interrupted = 'X'. * This means the last data object has not been saved. * -> Clean-up and/or update status specific to interrupted sessions, * but also write a detailed or standard log + close session as usual: ENDIF. * create the default spool list CALL FUNCTION 'ARCHIVE_WRITE_STATISTICS' EXPORTING archive_handle = handle. * close the archiving session CALL FUNCTION 'ARCHIVE_CLOSE_FILE' EXPORTING archive_handle = handle. Copyright 2001 SAP AG Page 16 of 16 Delete Program For an additional example of a delete program, see the RSARCH06 program. *-------------------------------------------------------------------------------------------------------- * * 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 to support random access. * * The related write pgm in archiving object BC_SBOOK is SBOOKA. * * For production use, you have to include proper exception handling. * * * * UNICODE-ENABLED * *-------------------------------------------------------------------------------------------------------- * REPORT sbookd. * data declaration CONSTANTS: object LIKE arch_obj-object VALUE 'BC_SBOOK'. DATA: handle LIKE sy-tabix, sel_files_itab TYPE TABLE OF arch_files, record_type LIKE arc_buffer-rname, buffer_ref TYPE REF TO data, " Unicode 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. FIELD-SYMBOLS: <sbook_ptr> TYPE sbook. " Unicode * <[further_structure]_ptr> TYPE [further_structure]. PARAMETERS: testrun DEFAULT 'X' AS CHECKBOX. " from database * open a new archiving session to delete data CALL FUNCTION 'ARCHIVE_OPEN_FOR_DELETE' EXPORTING object = object test_mode = testrun IMPORTING archive_handle = handle EXCEPTIONS OTHERS = 01. IF sy-subrc <> 0. WRITE / 'No file can be accessed'(001). EXIT. ENDIF. " do not delete * get Customizing data from the archiving object CALL FUNCTION 'ARCHIVE_GET_CUSTOMIZING_DATA' EXPORTING object = object IMPORTING commit_count_for_delete_prg = commit_cnt maintain_index = index_flag. Copyright 2001 SAP AG Page 17 of 17 * loop to get the next data object from the archive file(s) CLEAR object_cnt. DO. 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. ADD 1 TO object_cnt. * 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. * loop to get data records from ADK's data container DO. CALL FUNCTION 'ARCHIVE_GET_NEXT_RECORD' EXPORTING archive_handle = handle IMPORTING record_structure = record_type record_ref = buffer_ref " Unicode EXCEPTIONS end_of_object = 01. IF sy-subrc = 1. EXIT. ENDIF. * keep data records in mind; take their structure into account CASE record_type. WHEN 'SBOOK'. ASSIGN buffer_ref->* TO <sbook_ptr>. " Unicode APPEND <sbook_ptr> TO sbook_itab. " will be deleted in db * when ... " further structures ENDCASE. ENDDO. IF testrun IS INITIAL AND object_cnt EQ 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 GE 1. PERFORM delete_from_table. " deleting last package Copyright 2001 SAP AG Page 18 of 18 ENDIF. * create statistics list when production mode IF testrun IS INITIAL. CALL FUNCTION 'ARCHIVE_WRITE_STATISTICS' EXPORTING archive_handle = handle statistics_only_per_file = 'X'. ENDIF. * 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 archiving 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, stat_itab *---------------------------------------------------------------------* FORM delete_from_table. REFRESH stat_itab. DELETE sbook FROM TABLE sbook_itab. " delete job restartable tabfield-tabname = ' '. tabfield-count = object_cnt. APPEND tabfield TO stat_itab. tabfield-tabname = 'SBOOK'. tabfield-count = sy-dbcnt. APPEND tabfield TO stat_itab. CALL FUNCTION 'ARCHIVE_GIVE_STATISTICS' EXPORTING archive_handle = handle TABLES table = stat_itab. COMMIT WORK. 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. * Copyright 2001 SAP AG Page 19 of 19 INSERT arch_idx_s FROM TABLE index_tab. REFRESH index_tab. ENDFORM. " SAVE_INDEX_TAB Read Program For additional examples of read programs, see the RSARCH19, SBOOKR_2, and SBOOKR_3 programs. *-------------------------------------------------------------------------------------------------------- * * 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. * * * * THIS PROGRAM ALSO DEMONSTRATES HOW TO ENABLE A * * READ PROGRAM FOR U N I C O D E. * * * * Here we use TYPED field symbols to get the data back from ADK. * *-------------------------------------------------------------------------------------------------------- * REPORT sbookr. * data declaration DATA: handle LIKE sy-tabix, record_type LIKE arc_buffer-rname, * buffer LIKE arc_buffer-segment, " non-Unicode buffer_ref TYPE REF TO data, " Unicode * sbook_wa LIKE sbook, " no longer needed number_of_records_read TYPE i. FIELD-SYMBOLS: <sbook_ptr> TYPE sbook. " Unicode * <[further_structure]_ptr> TYPE [further_structure]. * 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. Copyright 2001 SAP AG Page 20 of 20 IF sy-subrc <> 0. EXIT. ENDIF. * get data records from the data container DO. CALL FUNCTION 'ARCHIVE_GET_NEXT_RECORD' EXPORTING archive_handle = handle IMPORTING record_structure = record_type * record = buffer " non-Unicode record_ref = buffer_ref " Unicode 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 record_type. WHEN 'SBOOK'. * sbook_wa = buffer. " non-Unicode * 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, * / '...'. ASSIGN buffer_ref->* TO <sbook_ptr>. " Unicode WRITE: / 'CARRID :', <sbook_ptr>-carrid, / 'BOOKID :', <sbook_ptr>-bookid, / 'CONNID :', <sbook_ptr>-connid, / 'FLDATE :', <sbook_ptr>-fldate, / 'CUSTOMID :', <sbook_ptr>-customid, / 'ORDER_DATE:', <sbook_ptr>-order_date, / '...'. * when ... * If the archiving object contained more than one table, such as * different record_types, more cases would be needed. ENDCASE. * close the archiving session CALL FUNCTION 'ARCHIVE_CLOSE_FILE' EXPORTING archive_handle = handle. Copyright 2001 SAP AG Page 21 of 21
Report "ADK - Data Archiving and Archive Development Kit"