Archiving in SAP for Developers

Archiving is using program or archiving object .Archive data is also accessed using archiving information system Archive Information System (SAP AS) and DART (data retention tool)

In archiving all the records belongs to the archiving objects are written together to archive file and then deleted from database tables.

Data archiving process is composed of two steps
·        Creation of archive files
·        Deletion of data

Structure Definition: Describes which underlying tables are processed during data archiving.

How to fetch records from AS (Archive Info system )

Definition (AS) Archive Info system:
The Archive Information System (AS) is a generic tool for indexing data archives and is fully integrated into the SAP Data Archiving environment. The indexes created with this tool, which are called Archive Information Structures, are used to display archived data.

Get the archived info source SAP_BC_SBOOK01 go to tcode SARJ















Goto-> Technical data Get the underlying structure table Z*

Archiving Object :
The archiving object is a central component of SAP Data Archiving. The archiving object specifies precisely which data is archived and how. It describes which database objects must be handled together as a single business object. And interprets the data irrespective of the technical specifications at the time of archiving (such as release and hardware).

Ex:Go to SARE tcode :archiving Object BC_SBOOK.



There are two methods to fetch data from archive system.
When we need read one tables or when we need records from different tables.

Case 1: when we need to fetch records from AS table SBOOK only.

In this case we have Archive Object BC_SBOOK and we need records from only one table ie SBOOK.
Go to DB15à tcode for BC_SBOOK we have three tables SBOOK,UDM_P2P_ATTR and USMCASEATTR00.


We will use direct fetch method as below:
 Direct fetch from AIS info objects
There is mapping table aind_str2 with AIS name
Here GENTAB will have of the underlying Ztable name.

DATA :lv_arch_ind     TYPE aind_fcat   VALUE 'SAP_BC_SBOOK01'."Airchive info source name
Data:lv_gen_tab TYPE aind_str2-gentab.

*get the generated archive table generated
  SELECT SINGLE gentab INTO lv_gen_tab
  FROM aind_str2
  WHERE archindex =  lv_arch_ind
   AND active = abap_true.
  IF sy-subrc EQ 0.
*use same selection criteria for live data as well as archive data
      SELECT *
      APPENDING CORRESPONDING FIELDS OF TABLE gt_SFLIGHT
      FROM (lv_gen_tab)
         WHERE CARRID =  'A'
      IF sy-subrc EQ 0.
      ENDIF.
    ENDIF.






Case 2: When we need to fetch data from All the three tables SBOOK,UDM_P2P_ATTR and USMCASEATTR00.Use FM 'ARCHIVE_GET_NEXT_RECORD' and filter the data based on the tables.
Sample program to fetch data from archive system using function module



DATA :g_sel TYPE rsds_frange_t.
DATAls_sel TYPE rsds_frange.
DATA :
  gr_alv     TYPE REF TO cl_salv_table,
  gr_columns TYPE REF TO cl_salv_columns_table.
DATA ra_selopt TYPE rsdsselopt .
DATA lt_selopt TYPE  STANDARD TABLE OF rsdsselopt .

DATA:
  BEGIN OF g_sbook,
    carrid LIKE sbook-carrid,
    bookid LIKE sbook-bookid,
  END OF g_sbook,
  gt_result TYPE TABLE OF aind_arkey.
DATA :ls_result  TYPE  aind_arkey.
DATA :lv_handle TYPE sy-tabix.
DATA :lv_length  TYPE i.
DATA :ls_record TYPE sbook.
DATA :ls_structure TYPE arc_buffer-rname.
DATA :gt_alv TYPE STANDARD TABLE OF sbook.

SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
PARAMETERS :carrid TYPE sbook-carrid.
PARAMETER :bookid TYPE sbook-bookid.
PARAMETERS:c_cb1 AS CHECKBOX.
PARAMETERS :c_cb2 AS CHECKBOX.

SELECTION-SCREEN END OF BLOCK b1.

 g_sbook-carrid carrid.
g_sbook-bookid bookid.
ra_selopt-sign 'I'.
ra_selopt-option 'EQ'.
ra_selopt-low  carrid.
APPEND ra_selopt TO lt_selopt.

g_sbook-carrid carrid.
g_sbook-bookid bookid.
ra_selopt-sign 'I'.
ra_selopt-option 'EQ'.
ra_selopt-low  bookid.
APPEND ra_selopt TO lt_selopt.

ls_sel-fieldname 'CARRID'.
ls_sel-selopt_t  lt_selopt.
APPEND ls_sel TO g_sel.
CLEAR ls_sel.

CALL FUNCTION 'AS_API_READ'
  EXPORTING
    i_fieldcat   'SAP_BC_SBOOK01'"Field catalog name
    i_selections g_sel
  IMPORTING
    e_result     gt_result.

IF sy-subrc 0.
  READ TABLE gt_result INTO ls_result INDEX 1.
  CALL FUNCTION 'ARCHIVE_READ_OBJECT'
    EXPORTING
      object                    'BC_SBOOK'
      archivkey                 ls_result-archivekey
      offset                    ls_result-archiveofs
    IMPORTING
      archive_handle            lv_handle
      compr_object_length       lv_length
    EXCEPTIONS
      no_record_found           1
      file_io_error             2
      internal_error            3
      open_error                4
      cancelled_by_user         5
      archivelink_error         6
      object_not_found          7
      filename_creation_failure 8
      file_already_open         9
      not_authorized            10
      file_not_found            11
      OTHERS                    12.
  IF sy-subrc <> 0.
* Implement suitable error handling here
  ENDIF.

ENDIF.

CALL FUNCTION 'ARCHIVE_GET_NEXT_RECORD'
  EXPORTING
    archive_handle          lv_handle
    get_real_structure_name lv_length
  IMPORTING
    record                  ls_record
    record_structure        ls_structure
  EXCEPTIONS
    end_of_object           1
    internal_error          2
    wrong_access_to_archive 3
    OTHERS                  4.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.


*Display alv
If ls_structure eq 'SFLIGHT'   
APPEND ls_record TO gt_alv.
CLEAR ls_record.
Else ls_structure eq ' UDM_P2P_ATTR '
APPEND ls_record_2 TO gt_alv2.
CLEAR ls_record_2.
 Endif.

*This id for GT_ALV
CALL METHOD cl_salv_table=>factory
  IMPORTING
    r_salv_table gr_alv
  CHANGING
    t_table      gt_alv.
gr_columns gr_alv->get_columns( ).

CALL METHOD gr_alv->display.


 Protected by Copyscape Web Copyright Checker