CBO Table Archiving 방법
CBO 테이블 아카이빙 방법을 설명합니다.
0. Archive Development KIT Package : SARC
1. 주요 Step
– 대상테이블 분석(TAANA/DB15) –> Archiving Object 생성(AOBJ) –> 아카이빙 프로그램 개발 –> 아카이빙 수행(SARA)
– SAP Archiving Introduction 문서 : Download
– DB15 관련 게시물 : http://itpe.me/414
– TAANA 관련 게시물 : http://itpe.me/415
2. Archiving Object 생성(Transaction : AOBJ)
3. 아카이빙 프로그램 샘플
– Read (Standard Program : RSAADMLE)
[#M_소소코드 보기|접기|
************************************************************************
* Program : ZZELTUP01A_RED *_M#]
* Author : leejhy *
* Date : 2007.02.05 *
* Functional description : ARCHIVE – READ Program *
* OBJECT : Z_ZPA01A *
************************************************************************REPORT zzeltup01a_red.
*———————————————————————-*
* data declaration
*———————————————————————-*
TABLES: zeltup01a.DATA: lt_zeltup01a TYPE TABLE OF zeltup01a,
lt_zeltup01a_tmp TYPE TABLE OF zeltup01a.
DATA: handle LIKE sy-tabix.FIELD-SYMBOLS: <ls_zeltup01a> TYPE zeltup01a.
*———————————————————————-*
* SELECT-OPTIONS / PARAMETER *
*———————————————————————-*
SELECTION-SCREEN BEGIN OF BLOCK arch_booking WITH FRAME TITLE text-101.
PARAMETERS: p_ERKRS TYPE ERKRS.
SELECT-OPTIONS: o_perio FOR zeltup01a-perio OBLIGATORY NO INTERVALS
NO-EXTENSION,
o_zck01 FOR zeltup01a-zck01,
o_zck02 FOR zeltup01a-zck02.
SELECTION-SCREEN END OF BLOCK arch_booking.*———————————————————————-*
* START-OF-SELECTION *
*———————————————————————-*
* open existing archive files
CALL FUNCTION ‘ARCHIVE_OPEN_FOR_READ’
EXPORTING
object = ‘Z_ZPA01A’
IMPORTING
archive_handle = handle
EXCEPTIONS
OTHERS = 1.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE ‘I’ NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
EXIT.
ENDIF.* 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. “nur die Ausnahmen, auf die man
IF sy-subrc <> 0. “wirklich reagieren will
EXIT.
ENDIF.* get data records from the data container ZELTUP01a
CALL FUNCTION ‘ARCHIVE_GET_TABLE’
EXPORTING
archive_handle = handle
record_structure = ‘ZELTUP01A’
all_records_of_object = ‘X’
TABLES
table = lt_zeltup01a_tmp
EXCEPTIONS
end_of_object = 0. “not entries of this type* check lt_ZELTUP01a_tmp entries against selections.
* Delete not requested entries
LOOP AT lt_zeltup01a_tmp ASSIGNING <ls_zeltup01a>
WHERE perio IN o_perio AND
zck01 IN o_zck01 AND
zck02 IN o_zck02.
APPEND <ls_zeltup01a> TO lt_zeltup01a.
ENDLOOP.
REFRESH lt_zeltup01a_tmp.ENDDO.
* Call ABAP List Viewer (ALV)
CALL FUNCTION ‘REUSE_ALV_GRID_DISPLAY’
EXPORTING
i_structure_name = ‘ZELTUP01A’
TABLES
t_outtab = lt_zeltup01a.* close the archiving session
CALL FUNCTION ‘ARCHIVE_CLOSE_FILE’
EXPORTING
archive_handle = handle.*&———————————————————————*
*& Form get_db
*&———————————————————————*
FORM get_db .
SELECT * FROM zeltup01a
APPENDING CORRESPONDING FIELDS OF TABLE lt_zeltup01a
WHERE erkrs = P_ERKRS AND
perio IN o_perio AND
zck01 IN o_zck01 AND
zck02 IN o_zck02.ENDFORM. ” get_db
– Write (Stanard Program : RSAADMAR)
[#M_소스코드 보기|접기|
************************************************************************
* Program : ZZELTUP01A_REL *
* Author : leejhy *
* Date : 2007.02.05 *
* Functional description : ARCHIVE – WRITE Program *
* OBJECT : Z_ZPA01A *
************************************************************************
report ZZELTUP01A_WRI.*———————————————————————-*
* data declaration
*———————————————————————-*
tables: ZELTUP01a.data: button(1) type c,
create(1) type c value ‘X’,
no_delete(1) type c value ‘X’,
handle like sy-tabix,
ZELTUP01a_itab type table of ZELTUP01a with header line,
data_object_id like arch_idx_s-obj_id.*———————————————————————-*
* SELECT-OPTIONS / PARAMETER *
*———————————————————————-*
selection-screen begin of block arch_booking with frame title text-101.
PARAMETERS: P_ERKRS TYPE ERKRS.
select-options: o_perio for ZELTUP01a-perio obligatory no intervals
no-extension,
o_zck01 for ZELTUP01a-zck01,
o_zck02 for ZELTUP01a-zck02.
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’.
selection-screen end of block arch_control.
parameters comments type admi_text lower case.
*default ‘Test data for archiving with Z_ZELTUP01A'(105).*———————————————————————-*
* START-OF-SELECTION *
*———————————————————————-*DATA: g_CURSOR TYPE CURSOR,
g_package TYPE i VALUE 5000.* build ADK parameters from chosen button
if no_file = ‘X’. create = ‘ ‘. no_delete = ‘ ‘. endif.
if del_test = ‘X’. create = ‘X’. no_delete = ‘X’. endif.* open a new archive 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 = ‘Z_ZPA01A’
importing
archive_handle = handle.* select data from the database – 20070212 new ->
OPEN CURSOR WITH HOLD g_CURSOR FOR
select * from ZELTUP01A
where erkrs = P_ERKRS and
perio in o_perio and
zck01 in o_zck01 and
zck02 in o_zck02.
DO.
*” Package size ŭ о internal table ZELTUP01A_itab ִ´.
FETCH NEXT CURSOR g_CURSOR
INTO CORRESPONDING FIELDS OF TABLE ZELTUP01A_itab
PACKAGE SIZE G_PACKAGE.IF SY-SUBRC = 4. EXIT. ENDIF.
* select data from the database – 20070212 new <-loop at ZELTUP01A_itab.
concatenate sy-mandt ZELTUP01A_itab-perio ZELTUP01A_itab-zck01
ZELTUP01A_itab-zck02 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 = ‘ZELTUP01A’
record = ZELTUP01A_itab.* write data object into the archive file
call function ‘ARCHIVE_SAVE_OBJECT’
exporting
archive_handle = handle.endloop.
clear: ZELTUP01A_itab[].
ENDDO. ” 20070212 new
CLOSE CURSOR g_CURSOR. ” 20070212 new
* create the default spool list
call function ‘ARCHIVE_WRITE_STATISTICS’
exporting
archive_handle = handle.
* close the archive session
call function ‘ARCHIVE_CLOSE_FILE’
exporting
archive_handle = handle.
– Delete (Standard Program : RSAADMLO)
[#M_소스코드 보기|접기|
************************************************************************
* Program : ZZELTUP01A_DEL *
* Author : leejhy *
* Date : 2007.02.05 *
* Functional description : ARCHIVE – DELETE Program *
* OBJECT : Z_ZPA01A *
************************************************************************
REPORT ZZELTUP01A_DEL.
CONSTANTS: OBJECT LIKE ARCH_OBJ-OBJECT VALUE ‘Z_ZPA01A’.
DATA: HANDLE LIKE SY-TABIX,
BUFFER TYPE ARC_BUFFER,
SEL_FILES_ITAB TYPE TABLE OF ARCH_FILES,
ZELTUP01A_WA LIKE ZELTUP01A,
ZELTUP01A_TTAB TYPE TABLE OF ZELTUP01A,
ZELTUP01A_ITAB TYPE TABLE OF ZELTUP01A,
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.
DATA: ITABNAME(20) TYPE C.
FIELD-SYMBOLS: <TS> TYPE TABLE.
*———————————————————————-*
* SELECT-OPTIONS / PARAMETER *
*———————————————————————-*
PARAMETERS: TESTRUN DEFAULT ‘X’ AS CHECKBOX. ” do not delete
” from database
* open a new archive session to delete data
CALL FUNCTION ‘ARCHIVE_OPEN_FOR_DELETE’
EXPORTING
OBJECT = OBJECT
TEST_MODE = TESTRUN
IMPORTING
ARCHIVE_HANDLE = HANDLE
EXCEPTIONS
OTHERSQ = 01.
IF SY-SUBRC <> 0.
WRITE / ‘No file can be accessed'(001).
EXIT.
ENDIF.
* get customizing data from the archive object
CALL FUNCTION ‘ARCHIVE_GET_CUSTOMIZING_DATA’
EXPORTING
OBJECT = OBJECT
IMPORTING
COMMIT_COUNT_FOR_DELETE_PRG = COMMIT_CNT
MAINTAIN_INDEX = INDEX_FLAG.
* loop to get the next data object from the archive file(s)
CLEAR: OBJECT_CNT, COMMIT_CNT.
DO.
ADD 1 TO OBJECT_CNT.
ADD 1 TO COMMIT_CNT.
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.
* 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
CALL FUNCTION ‘ARCHIVE_GET_NEXT_RECORD’
EXPORTING
ARCHIVE_HANDLE = HANDLE
IMPORTING
RECORD = BUFFER-SEGMENT
RECORD_STRUCTURE = BUFFER-RNAME
EXCEPTIONS
END_OF_OBJECT = 01.
IF SY-SUBRC = 1.
EXIT.
ENDIF.
* keep data records in mind; take their structure into account
CASE BUFFER-RNAME.
WHEN ‘ZELTUP01A’.
CALL FUNCTION ‘ARCHIVE_GET_TABLE’
EXPORTING
ARCHIVE_HANDLE = HANDLE
RECORD_STRUCTURE = ‘ZELTUP01A’
ALL_RECORDS_OF_OBJECT = ‘X’
TABLES
TABLE = ZELTUP01A_TTAB[].
IF NOT ZELTUP01A_TTAB[] IS INITIAL.
LOOP AT ZELTUP01A_TTAB INTO ZELTUP01A_WA.
APPEND ZELTUP01A_WA TO ZELTUP01A_ITAB.
ENDLOOP.
ENDIF.
ENDCASE.
CLEAR BUFFER-SEGMENT.
IF TESTRUN IS INITIAL AND OBJECT_CNT = 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 >= 1.
PERFORM DELETE_FROM_TABLE. ” deleting last package
ENDIF.
* provide statistics
TABFIELD-TABNAME = ‘ ‘.
TABFIELD-COUNT = SUM_OBJECTS.
APPEND TABFIELD TO STAT_ITAB.
TABFIELD-TABNAME = ‘ZELTUP01A’.
APPEND TABFIELD TO STAT_ITAB.
CALL FUNCTION ‘ARCHIVE_GIVE_STATISTICS’
EXPORTING
ARCHIVE_HANDLE = HANDLE
TABLES
TABLE = STAT_ITAB.
* write statistics
CALL FUNCTION ‘ARCHIVE_WRITE_STATISTICS’
EXPORTING
ARCHIVE_HANDLE = HANDLE
STATISTICS_ONLY_PER_FILE = ‘X’.
* 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 archive 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 *
* ———————————————- *
FORM DELETE_FROM_TABLE.
DATA: TABCOUNT TYPE I VALUE 0.
DELETE ZELTUP01A FROM TABLE ZELTUP01A_ITAB. ” delete job restartable
COMMIT WORK.
DESCRIBE TABLE ZELTUP01A_ITAB LINES TABCOUNT.
SUM_OBJECTS = SUM_OBJECTS + TABCOUNT.
REFRESH ZELTUP01A_ITAB.
ENDFORM. ” DELETE_FROM_TABLE
* ———————————————- *
* Form SAVE_INDEX_TAB *
* ———————————————- *
* global: index_tab
* ———————————————- *
FORM SAVE_INDEX_TAB.
DELETE ARCH_IDX_S FROM TABLE INDEX_TAB.
INSERT ARCH_IDX_S FROM TABLE INDEX_TAB.
REFRESH INDEX_TAB.
ENDFORM. ” SAVE_INDEX_TAB
– Reload (Standard Program : RSAADMRL)
[#M_소스코드 보기|접기|
************************************************************************
* Program : ZZELTUP01A_REL *
* Author : leejhy *
* Date : 2007.02.05 *
* Functional description : ARCHIVE – RELOAD Program *
* OBJECT : Z_ZPA01A *
************************************************************************
REPORT zzeltup01a_rel.
*———————————————————————-*
* data declaration
*———————————————————————-*
CONSTANTS: object LIKE arch_obj-object VALUE ‘Z_ZPA01A’.
DATA: read_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
commit_cnt LIKE arch_usr-arch_comit,
object_cnt TYPE i,
read_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,
stat_itab TYPE TABLE OF arch_stat,
tabfield LIKE arch_stat.
DATA : BEGIN OF zeltup01a_itab OCCURS 0.
INCLUDE STRUCTURE zeltup01a.
DATA : END OF zeltup01a_itab.
FIELD-SYMBOLS: <zeltup01a_ptr> TYPE zeltup01a. ” Unicode
*———————————————————————-*
* SELECT-OPTIONS / PARAMETER *
*———————————————————————-*
PARAMETERS testmode DEFAULT ‘X’ AS CHECKBOX.
* open a new archiving session to reload data
CALL FUNCTION ‘ARCHIVE_OPEN_FOR_MOVE’
EXPORTING
object = object
test_mode = testmode
IMPORTING
archive_read_handle = read_handle
EXCEPTIONS
OTHERS = 01.
IF sy-subrc <> 0.
WRITE / ‘No file can be accessed'(001).
EXIT.
ENDIF.
* get Customizing data from the archiving object
CALL FUNCTION ‘ARCHIVE_GET_CUSTOMIZING_DATA’
EXPORTING
object = object
IMPORTING
commit_count_for_delete_prg = commit_cnt.
* 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 = read_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.
MOVE: object_id TO index_tab-obj_id,
arkey TO index_tab-archivekey,
offset TO index_tab-obj_offset.
APPEND index_tab.
PERFORM delete_index_tab ON COMMIT.
* loop to get data records from ADK’s data container
DO.
CALL FUNCTION ‘ARCHIVE_GET_NEXT_RECORD’
EXPORTING
archive_handle = read_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 ‘ZELTUP01A’.
ASSIGN buffer_ref->* TO <zeltup01a_ptr>. ” Unicode
APPEND <zeltup01a_ptr> TO zeltup01a_itab. ” will be reloaded to db
ENDCASE.
ENDDO.
IF testmode IS INITIAL AND object_cnt EQ commit_cnt.
PERFORM insert_from_table. ” reload to database
CLEAR object_cnt. ” restart counting up to
ENDIF. ” value of commit counter
ENDDO.
IF testmode IS INITIAL AND object_cnt GE 1.
PERFORM insert_from_table. ” reloading records of last file
ENDIF.
* get all processed files for update of index status
CALL FUNCTION ‘ARCHIVE_GET_ARCHIVE_FILES’
EXPORTING
archive_handle = read_handle
TABLES
archive_files = sel_files_itab.
* create statistics list when production mode
IF testmode IS INITIAL.
CALL FUNCTION ‘ARCHIVE_WRITE_STATISTICS’
EXPORTING
archive_handle = read_handle.
ENDIF.
* close the archiving session
CALL FUNCTION ‘ARCHIVE_CLOSE_FILE’
EXPORTING
archive_handle = read_handle.
* set status “index deleted” in SARA administration
IF testmode IS INITIAL.
CALL FUNCTION ‘ARCHIVE_ADMIN_SET_STATUS’
EXPORTING
files_are_converted = ‘ ‘
index_deleted = ‘X’
TABLES
archive_files = sel_files_itab.
ENDIF.
*———————————————————————*
* FORM INSERT_FROM_TABLE *
*———————————————————————*
*global: ZELTUP01a_itab *
*———————————————————————*
FORM insert_from_table.
REFRESH stat_itab.
INSERT zeltup01a FROM TABLE zeltup01a_itab ACCEPTING DUPLICATE KEYS.
tabfield-tabname = ‘ ‘.
tabfield-count = object_cnt.
APPEND tabfield TO stat_itab.
tabfield-tabname = ‘ZELTUP01A’.
tabfield-count = sy-dbcnt.
APPEND tabfield TO stat_itab.
CALL FUNCTION ‘ARCHIVE_GIVE_STATISTICS’
EXPORTING
archive_handle = read_handle
TABLES
table = stat_itab.
COMMIT WORK.
REFRESH zeltup01a_itab.
ENDFORM. “insert_from_table
*———————————————————————*
* Form DELETE_INDEX_TAB *
*———————————————————————*
* global: index_tab *
*———————————————————————*
FORM delete_index_tab.
IF testmode IS INITIAL.
DELETE arch_idx_s FROM TABLE index_tab.
ENDIF.
REFRESH index_tab.
ENDFORM. ” DELETE_INDEX_TAB
–> 아카이빙 오브젝트에 Assign한 프로그램 ID로 생성합니다.
4. 아카이빙 수행(Transaction : SARA)