Introduction To Data Archiving
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:
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.
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
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
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
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.
" 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.