Sei sulla pagina 1di 12

Introduction to Data Archiving

Data archiving is an important aspect to be taken into account. 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, it should be done on a regular basis. Comprehensive achievability 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:

Figure 1: Database Volume Versus Archive Volume

Reasons for Data Archiving


Archiving data and the related reduction in the volume of active online data allows: Better performance Faster backup and recovery Faster release upgrades Faster analysis of database statistics (if a cost-based optimizer is used) Efficient use of resources Reduced hardware costs (fewer hard disks, less CPU, and memory capacity needed) Reduced administration costs Shorter response times in transactions

Archiving Process
SAPs 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. 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. Data 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 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. This 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, verification information can be written to the archive files along with the data. The system uses this 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 Archive Link 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.

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 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

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. Structure of a Write Program
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 ARCHIVE_CLOSE_FILE

Structure of a Delete Program


Declaration part DATABASE TABLES (tabA, tabB, tabC) INTERNAL TABLES (itabA, itabB, itabC) PARAMETERS Select all archive files for the archive object ARCH_SELECT_ALL 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

Structure of a Read Program


Declaration part DATABASE TABLES (tabA, tabB, tabC) INTERNAL TABLES (itabA, itabB, itabC) PARAMETERS Select all archive files for the archive object ARCH_SELECT_ALL Open a new archiving session to read 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

Archiving Function Modules


This list is not a complete list of all archiving function modules. 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).
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 ARCHIVE_SAVE_OBJECT

out in a delete or reload program, it must be done by calling this function module , not by the ABAP statement ROLLBACK WORK. 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.
ARCH_SELECT_ALL

This function module reads all archive files for a given archive object. Sample Program: Example of the routine for Archive reading t_range like rng_archiv occurs 10 with header line w_handle like sy-tabix, w_segment like arc_buffer-segment, w_struct_name like arc_buffer-rname *--------------------------------------------------------------------------------------------------------* archive data from all files, add into appropriate internal table *--------------------------------------------------------------------------------------------------------* form 09000_ get_archived_data *.. select all archive file

perform 09100_select_all_file. *..if there is at least 1 file selected, continue the process. otherwise skip the reading if not t_range[] is initial. call function 'archive_open_for_read' exporting object = (object name) importing archive_handle = w_handle tables archive_files = t_range exceptions file_already_open =1 file_io_error =2 internal_error =3 no_files_available =4 object_not_found =5 open_error =6 not_authorized =7 others = 8. if sy-subrc ne 0. exit. endif do. call function 'archive_get_next_object' exporting archive_handle = w_handle exceptions end_of_file =1 file_io_error =2 internal_error =3 open_error =4 wrong_access_to_archive =5 others = 6. if sy-subrc ne 0. exit. endif *get the individual archived records for the each segment do. call function 'archive_get_next_record' exporting archive_handle = w_handle importing

record = w_segment record_structure = w_struct_name exceptions end_of_object =1 internal_error =2 wrong_access_to_archive = 3 others = 4. if sy-subrc ne 0. exit. endif *the record is stored in the appropriate structure case w_struct_name. when 'MKPF'. move w_segment to t_mkpf. Append t_mkpf. when 'MSEG'. move w_segment to t_mseg. Append t_mseg. endcase enddo. enddo. Endif. Endform * After the records are stored in the appropriate structures, the archived records becomes * available to the program for use *--------------------------------------------------------------------------------------------------------* * Get all files from Archive File *--------------------------------------------------------------------------------------------------------* form 09100_select_all_file call function 'arch_select_all' exporting i_archobj = (object name) i_dialog_type = 'read' tables select_options = t_range exceptions no_files_found = 1 wrong_use_of_parameters = 2 others = 3. Endform

Archiving in Sapscript program


If Client/Business actually wants a copy of the form whenever they run the sapscript program, then the layout is to be saved as an Archive index. To archive the sapscript form we first need to call the function module GET_PRINT_PARAMMETERS. The function module GET_PRINT_PARAMETERS is used to define, modify and display the print and archive parameters. Using this function module is the only correct way to modify a print or archive parameter record. The archive and print parameters retrieved from this function module is passed to the function module OPEN_FORM. Finally, sapscript output parameters retrieved from OPEN_FORM is passed to the function module END_FORM. Once the archiving is done one can run the transaction OAAD to view the archived data. One important thing to note if you want an archived copy of the form every time you execute the driver program, then you cant expect to see the print preview of the corresponding form. But definitely a new spool request can be created every time you execute the program, where you can view the print preview of the output. In the example below we are creating an archived copy and a new spool request every time we run the driver program. Example of printing and archiving a form:
Tables: itcpo, itcpp, ztarch, toasp, zfarch, "SAPscript output interface "SAPscript output interface "Link table for archiving commercial letters "ArchiveLink Language Table For Archive Objects "Reports to be archived

parameters: p_copy LIKE pri_params-prcop OBLIGATORY, "No of copies required p_oupt LIKE nast-ldest OBLIGATORY. "Output device data: v_rimmd LIKE rfpdo2-f140immd VALUE 'X', "Print immediately sap_object LIKE toav0-sap_object, "Document type ar_object LIKE toav0-ar_object, "Business object c_armod(1) TYPE c VALUE '3', "Print: Archiving mode arch_params LIKE arc_params, "Archive parameters print_params LIKE pri_params, "Print parameters archive_text LIKE arc_params-arctext, "Commercial letter arch_dara LIKE toa_dara, "ArchiveLink structure lnr VALUE '0', save_rxopol TYPE c, C_FUNC(4) TYPE C VALUE 'DARA'. "name of function to be called FORM 8100_ALLOW_ARCHIVING USING P_DOCTYPE. CLEAR SAP_OBJECT. CLEAR ARCH_DARA-OBJECT_ID. *Determine sap object

SELECT SINGLE SAP_OBJECT INTO SAP_OBJECT FROM ZTARCH WHERE REPORT = SY-REPID AND AR_OBJECT = P_DOCTYPE. SELECT SINGLE * FROM zfarch WHERE repid = sy-repid. IF sy-subrc = 0. IF save_rxopol = 'X'. lnr = '1'. ENDIF. ENDIF. * Determine object type and document type for letter SELECT SINGLE * FROM ZTARCH WHERE REPORT = SY-REPID AND SAP_OBJECT = SAP_OBJECT AND LNR = LNR. IF SY-SUBRC = 0. MOVE ZTARCH-AR_OBJECT TO AR_OBJECT. SELECT SINGLE * FROM TOASP WHERE AR_OBJECT = AR_OBJECT AND LANGUAGE = SY-LANGU. MOVE TOASP-OBJECTTEXT TO ARCHIVE_TEXT. ELSE. MESSAGE E099(BA) WITH 'No entry in link table ZTARCH' 'for report' SY-REPID SPACE. ENDIF. * tdarmod: '2' = archiving / '3' = print and archive ITCPO-TDARMOD = C_ARMOD. * * * * Function module for requesting, determining and changing archive and print parameters - ARCH_PARAMS and PRINT_PARAMS respectively. The ARCH_PARAMS parameter contains results of the archiving CALL FUNCTION 'GET_PRINT_PARAMETERS' EXPORTING ARCHIVE_INFO = 'ARC' ARCHIVE_MODE = ITCPO-TDARMOD ARCHIVE_TEXT = ARCHIVE_TEXT SAP_OBJECT = SAP_OBJECT AR_OBJECT = AR_OBJECT NO_DIALOG = 'X' COPIES = P_COPY DESTINATION = P_OUPT EXPIRATION = 1 IMMEDIATELY = V_RIMMD IMPORTING OUT_ARCHIVE_PARAMETERS = ARCH_PARAMS OUT_PARAMETERS = PRINT_PARAMS VALID = VALID EXCEPTIONS ARCHIVE_INFO_NOT_FOUND = 1 INVALID_PRINT_PARAMS = 2 INVALID_ARCHIVE_PARAMS = 3 OTHERS = 4. IF SY-SUBRC <> 0. MESSAGE E099(BA) WITH 'Error in function GET_PRINT_PARAMETERS:' SY-SUBRC SPACE SPACE. ENDIF.

ENDFORM.

" 8100_ALLOW_ARCHIVING

FORM 8300_open_form. CLEAR arch_dara-object_id. * Parameters for ArchiveLink structure arch_dara-object_id = i_vbrk-vbeln. arch_dara-function = c_func. arch_dara-mandant = sy-mandt. arch_dara-sap_object = sap_object. arch_dara-ar_object = ar_object. * parameters for sapscript output interface *Print: Output device itcpo-tddest = print_params-pdest. *Spool: Number of copies. 2 = original + 1 copy itcpo-tdcopies = print_params-prcop. * tdimmed: 'X' = print immediately / space = print to spool itcpo-tdimmed = space. * tdarmod: '2' = archiving / '3' = print and archive itcpo-tdarmod = c_armod. * print: new spool request (list) itcpo-tdnewid = print_params-prnew. *Spool request: Name (R/2: Dataset) itcpo-tddataset = print_params-prdsn. *PRINT: Spool retention period itcpo-tdlifetime = '7'. * To this Function module we are passing archive parameters arch_params * retrieved from GET_PRINT_PARAMETERS for determining sapscript output * parameters ITCPP CALL FUNCTION 'OPEN_FORM' EXPORTING archive_index = arch_dara archive_params = arch_params dialog = form = Form_name language = sy-langu options = itcpo IMPORTING result = itcpp EXCEPTIONS canceled = 1 device = 2 form = 3 options = 4 unclosed = 5 mail_options = 6 more_params_needed_in_batch = 7 invalid_fax_number = 8 OTHERS = 9.

IF sy-subrc <> 0. ENDIF. ENDFORM. FORM 8600_end_form.

" 8300_OPEN_FORM

* We are passing the sapscript output parameters ITCPP to this * function module to carry out the final operations required on layout. * CAUTION: END_FORM is not a replacement for CLOSE_FORM. CALL FUNCTION 'END_FORM' IMPORTING result = EXCEPTIONS unopened = bad_pageformat_for_print = OTHERS = COMMIT WORK. ENDFORM. mandatory " 8600_END_FORM

itcpp 1 2 3.

Potrebbero piacerti anche