introduction to data archiving

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

Upload: amit-guglani

Post on 04-Mar-2015

295 views

Category:

Documents


8 download

TRANSCRIPT

Page 1: 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:

Figure 1: Database Volume Versus Archive Volume

Page 2: Introduction to Data Archiving

Reasons for Data ArchivingArchiving 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 ProcessSAP’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. 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. DataStep1: Write PhaseThe 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 PhaseThe 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 PhaseYou 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.

Page 3: Introduction to Data Archiving

Reading Archive FilesOnce 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 ToolsThe 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 ProgramsIn 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 ProgramDeclaration partDATABASE TABLES (tabA, tabB, tabC)INTERNAL TABLES (itabA, itabB, itabC)PARAMETERSSelect data from databaseSELECT * FROM tab INTO itabOpen a new archiving sessionARCHIVE_OPEN_FOR_WRITELoop (n = number of data objects/records in header table)LOOP n TIMES

Initialize data containerARCHIVE_NEW_OBJECTPut data records from itabA into data containerARCHIVE_PUT_RECORD

Page 4: Introduction to Data Archiving

Loop (m = number of records in itabB)LOOP m TIMES

Put data records from itabB into data containerARCHIVE_PUT_RECORD

ENDLOOPLoop (p = number of records in itabC)LOOP p TIMES

Put data records from itabC into data containerARCHIVE_PUT_RECORD

ENDLOOPWrite data objects to archive fileARCHIVE_SAVE_OBJECT

ENDLOOPCreate statisticsARCHIVE_WRITE_STATISTICSClose archiving sessionARCHIVE_CLOSE_FILE

Structure of a Delete ProgramDeclaration partDATABASE TABLES (tabA, tabB, tabC)INTERNAL TABLES (itabA, itabB, itabC)PARAMETERSSelect all archive files for the archive objectARCH_SELECT_ALLOpen a new archiving session to delete dataARCHIVE_OPEN_FOR_DELETEGet the commit counter belonging to the archive objectARCHIVE_GET_CUSTOMIZING_DATALoop (n = number of data objects in archive file)LOOP n TIMES

Get next object from the archive files into data containerARCHIVE_GET_NEXT_OBJECTLoop (r = number of records in data container)LOOP r TIMES

Get next data records from data container into ABAP reportARCHIVE_GET_NEXT_RECORD or ARCHIVE_GET_TABLE (better)

ENDLOOPDelete data (array delete according to commit counter)DELETE tab FROM itabARCHIVE_GIVE_STATISTICS

ENDLOOPClose the archiving sessionARCHIVE_CLOSE_FILE

Structure of a Read ProgramDeclaration partDATABASE TABLES (tabA, tabB, tabC)INTERNAL TABLES (itabA, itabB, itabC)PARAMETERSSelect all archive files for the archive objectARCH_SELECT_ALLOpen a new archiving session to read dataARCHIVE_OPEN_FOR_READLoop (n = number of data objects in archive file)

Page 5: Introduction to Data Archiving

LOOP n TIMESGet next object from the archive files into data containerARCHIVE_GET_NEXT_OBJECTLoop (r = number of records in data container)LOOP r TIMES

Get next data records from data container into ABAP reportARCHIVE_GET_NEXT_RECORD

ENDLOOPRead dataWRITE.

ENDLOOPClose the archiving sessionARCHIVE_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_FILEThis 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_DATAThis 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_OBJECTThis 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_RECORDThis function module sequentially reads the next record of a data object determined byARCHIVE_GET_NEXT_OBJECT. The first call automatically reads the first record from the data container.ARCHIVE_GIVE_STATISTICSThis 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_OBJECTThis 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_DELETEThis 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.

Page 6: Introduction to Data Archiving

ARCHIVE_OPEN_FOR_READThis 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_WRITEThis 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_RECORDThis 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_WORKIf 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_OBJECTThis function module writes a data object to an archive file. The data passed byARCHIVE_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_STATISTICSThis function module creates a statistics print-out for the data objects you have written to the archive files with ARCHIVE_SAVE_OBJECT.ARCH_SELECT_ALLThis function module reads all archive files for a given archive object.

Sample Program:Example of the routine for Archive readingt_range like rng_archiv occurs 10 with header linew_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 fileperform 09100_select_all_file.

Page 7: Introduction to Data Archiving

*..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.endifdo. 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

Page 8: Introduction to Data Archiving

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

Page 9: Introduction to Data Archiving

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 can’t 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, "SAPscript output interface itcpp, "SAPscript output interface ztarch, "Link table for archiving commercial letters toasp, "ArchiveLink Language Table For Archive Objects zfarch, "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 objectc_armod(1) TYPE c VALUE '3', "Print: Archiving modearch_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 structurelnr 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

Page 10: Introduction to Data Archiving

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.

Page 11: Introduction to Data Archiving

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.

Page 12: Introduction to Data Archiving

IF sy-subrc <> 0. ENDIF. ENDFORM. " 8300_OPEN_FORM

FORM 8600_end_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 = itcpp EXCEPTIONS unopened = 1 bad_pageformat_for_print = 2 OTHERS = 3. COMMIT WORK. “mandatory ENDFORM. " 8600_END_FORM