REPORT YARCHTEST_REL MESSAGE-ID YAPK
NO STANDARD PAGE HEADING
LINE-SIZE 255.
*- Tables Declarations.
TABLES: YAPTMAIN.
TYPE-POOLS SLIS.
*- Internal Table Declarations....................................
DATA: BEGIN OF I_YAPTMAIN OCCURS 0.
INCLUDE STRUCTURE YAPTMAIN .
DATA: END OF I_YAPTMAIN.
DATA: I_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV.
DATA: I_EVENTS TYPE SLIS_T_EVENT.
DATA: I_INDEX_TAB TYPE TABLE OF ARCH_IDX_S WITH HEADER LINE.
DATA: I_SEL_FILES_ITAB TYPE TABLE OF ARCH_FILES.
*- Structures.......................................................
DATA: BEGIN OF K_BUFFER.
INCLUDE STRUCTURE arc_buffer.
DATA: END OF K_BUFFER,
K_TABLE_WA LIKE YAPTMAIN.
*- Structure for Layout.
DATA: X_LAYOUT TYPE SLIS_LAYOUT_ALV.
DATA:V_READ_HANDLE LIKE sy-tabix,
v_exi TYPE c,
v_x TYPE c VALUE 'X',
v_returncode TYPE c,
V_COMMIT_CNT LIKE ARCH_USR-ARCH_COMIT,
V_OBJECT_CNT TYPE I,
V_READ_CNT TYPE I,
V_RELOAD_CNT TYPE I,
V_ARKEY LIKE ARCH_IDX_S-ARCHIVEKEY,
V_OBJECT_ID LIKE ARCH_IDX_S-OBJ_ID,
V_OFFSET LIKE ARCH_IDX_S-OBJ_OFFSET,
V_DUPREC TYPE C,
V_I_TAB TYPE SLIS_TABNAME.
*--Constants........................................................
CONSTANTS: C_0 VALUE 0,
C_SPACE VALUE SPACE,
C_1 VALUE 1,
C_4 VALUE 4,
C_X VALUE 'X',
C_TOP_OF_LIST(15) VALUE 'TOP_OF_LIST',
C_TOP_OF_LIST_YAPTMAIN(35) VALUE 'TOP_OF_LIST_YAPTMAIN',
C_I_YAPTMAIN(35) VALUE 'I_YAPTMAIN',
C_MSG1(25) VALUE 'No file can be accessed',
C_MSG2(40) VALUE 'Unable to access customizing data',
C_MSG3(25) VALUE 'Unable to Process Files',
C_TEXT1(25) VALUE 'There were duplicate keys',
C_TEXT2(25) VALUE 'RELOADED ARCHIVE INFO:',
C_TEXT3(25) VALUE 'Data Objects Read',
C_TEXT4(25) VALUE 'Data Objects Reloaded',
C_TEXT5(50) VALUE ' Reloaded Records for Object - YARCHTEST ' ,
C_TEXT6(50) VALUE ' YAPTMAIN - Archive Objects Information ' ,
C_TEXT7(15) VALUE 'Test Run',
C_TABLE(30) VALUE 'YAPTMAIN',
C_OBJECT(10) VALUE 'YARCHTEST'.
*- Selection Screen.
SELECTION-SCREEN BEGIN OF BLOCK B2 WITH FRAME TITLE V_TEXT2.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT (29) V_TEST.
PARAMETERS: TESTRUN DEFAULT'X' AS CHECKBOX.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK B2.
INITIALIZATION.
SY-TITLE = ' Reload Records for Object - YARCHTEST'.
V_TEXT2 = 'Test Run'.
CONCATENATE '''' C_I_YAPTMAIN '''' INTO V_I_TAB.
CONDENSE V_I_TAB NO-GAPS.
*- Get Selection Screen Texts.
PERFORM GET_SELECTION_TEXTS.
*- Popuate the layout structure for display.
PERFORM POPULATE_LAYOUT.
START-OF-SELECTION.
PERFORM OPEN_ARCHIVE_FILE.
PERFORM GET_CUSTOMIZING_DATA.
CLEAR: V_OBJECT_CNT, V_DUPREC, V_READ_CNT, V_RELOAD_CNT.
DO.
ADD 1 TO V_OBJECT_CNT.
CALL FUNCTION 'ARCHIVE_GET_NEXT_OBJECT'
EXPORTING
ARCHIVE_HANDLE = V_READ_HANDLE
IMPORTING
OBJECT_ID = V_OBJECT_ID
OBJECT_OFFSET = V_OFFSET
ARCHIVE_NAME = V_ARKEY
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 <> C_0.
EXIT.
ENDIF.
ADD 1 TO V_READ_CNT.
MOVE: V_OBJECT_ID TO I_INDEX_TAB-OBJ_ID,
V_ARKEY TO I_INDEX_TAB-ARCHIVEKEY,
V_OFFSET TO I_INDEX_TAB-OBJ_OFFSET.
APPEND I_INDEX_TAB.
PERFORM DELETE_INDEX_TAB ON COMMIT.
DO.
CALL FUNCTION 'ARCHIVE_GET_NEXT_RECORD'
EXPORTING
ARCHIVE_HANDLE = V_READ_HANDLE
IMPORTING
RECORD = K_BUFFER-SEGMENT
RECORD_STRUCTURE = K_BUFFER-RNAME
EXCEPTIONS
END_OF_OBJECT = 1
INTERNAL_ERROR = 2
WRONG_ACCESS_TO_ARCHIVE = 3
OTHERS = 4.
IF SY-SUBRC <> C_0.
EXIT.
ENDIF.
CASE K_BUFFER-rname.
WHEN C_TABLE.
MOVE K_BUFFER-SEGMENT TO K_TABLE_WA.
APPEND K_TABLE_WA TO I_YAPTMAIN.
ENDCASE.
ENDDO.
IF V_OBJECT_CNT = V_COMMIT_CNT.
PERFORM INSERT_FROM_TABLE.
CLEAR V_OBJECT_CNT.
ENDIF.
ENDDO.
IF V_OBJECT_CNT > C_1.
PERFORM INSERT_FROM_TABLE.
ENDIF.
PERFORM GET_ARCHIVE_FILE.
PERFORM CLOSE_ARCHIVE_FILE.
END-OF-SELECTION.
PERFORM WRITE_STATISTICS.
*- Output the data using ALV.
PERFORM OUTPUT_DATA_USING_ALV.
*& ---------------------------------------------------------*
*& Form ARCHIVE_OPEN_FOR_READ
*&----------------------------------------------------------*
* ARCHIVE_OPEN_FOR_READ
*& ---------------------------------------------------------*
FORM OPEN_ARCHIVE_FILE.
CALL FUNCTION 'ARCHIVE_OPEN_FOR_MOVE'
EXPORTING
object = C_OBJECT
TEST_MODE = TESTRUN
IMPORTING
archive_READ_handle = V_READ_HANDLE
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 > C_0.
MESSAGE I001 WITH C_MSG1.
EXIT.
ENDIF.
ENDFORM.
*& ---------------------------------------------------------*
*& Form GET_CUSTOMIZING_DATA
*&----------------------------------------------------------*
* GET_CUSTOMIZING_DATA
*& ---------------------------------------------------------*
FORM GET_CUSTOMIZING_DATA.
CALL FUNCTION 'ARCHIVE_GET_CUSTOMIZING_DATA'
EXPORTING
object = c_object
IMPORTING
COMMIT_COUNT_FOR_DELETE_PRG = V_COMMIT_CNT
EXCEPTIONS
OBJECT_NOT_FOUND = 1
OTHERS = 2.
IF SY-SUBRC > C_0.
MESSAGE I001 WITH C_MSG2.
EXIT.
ENDIF.
ENDFORM.
*& ---------------------------------------------------------*
*& Form GET_ARCHIVE_FILE
*&----------------------------------------------------------*
* GET_ARCHIVE_FILE
*& ---------------------------------------------------------*
FORM GET_ARCHIVE_FILE.
CALL FUNCTION 'ARCHIVE_GET_ARCHIVE_FILES'
EXPORTING
ARCHIVE_HANDLE = V_READ_HANDLE
TABLES
ARCHIVE_FILES = I_SEL_FILES_ITAB
EXCEPTIONS
WRONG_ACCESS_TO_ARCHIVE = 1
INTERNAL_ERROR = 2
OTHERS = 3.
IF SY-SUBRC <> C_0.
MESSAGE I001 WITH C_MSG3.
EXIT.
ENDIF.
ENDFORM.
*& ---------------------------------------------------------*
*& Form WRITE_STATISTICS
*&----------------------------------------------------------*
* Set administration status and write statistics
*& ---------------------------------------------------------*
FORM WRITE_STATISTICS.
IF TESTRUN IS INITIAL.
CALL FUNCTION 'ARCHIVE_ADMIN_SET_STATUS'
EXPORTING
FILES_ARE_CONVERTED = C_SPACE
INDEX_DELETED = C_X
TABLES
ARCHIVE_FILES = I_SEL_FILES_ITAB
EXCEPTIONS
CANNOT_CHANGE_STATUS = 1
OTHERS = 2.
ENDIF.
IF V_DUPREC <> C_SPACE.
WRITE:/ C_TEXT1.
ENDIF.
ULINE. WRITE:/ C_TEXT2. ULINE.
WRITE:/ V_READ_CNT, C_TEXT3.
WRITE:/ V_RELOAD_CNT, C_TEXT4.
ENDFORM.
*& ---------------------------------------------------------*
*& Form DELETE_INDEX_TAB
*&----------------------------------------------------------*
* DELETE_INDEX_TAB
*& ---------------------------------------------------------*
FORM DELETE_INDEX_TAB.
IF TESTRUN IS INITIAL.
DELETE ARCH_IDX_S FROM TABLE I_INDEX_TAB.
ENDIF.
REFRESH I_INDEX_TAB.
ENDFORM.
*& ---------------------------------------------------------*
*& Form INSERT_FROM_TABLE
*&----------------------------------------------------------*
* INSERT_FROM_TABLE
*& ---------------------------------------------------------*
FORM INSERT_FROM_TABLE.
IF TESTRUN IS INITIAL.
INSERT YAPTMAIN FROM TABLE I_YAPTMAIN
ACCEPTING DUPLICATE KEYS.
IF SY-SUBRC = C_4.
V_DUPREC = C_X.
ENDIF.
ADD SY-DBCNT TO V_RELOAD_CNT.
ENDIF.
COMMIT WORK.
ENDFORM.
*& ---------------------------------------------------------*
*& Form POPULATE_LAYOUT
*&----------------------------------------------------------*
* POPULATE_LAYOUT
*& ---------------------------------------------------------*
FORM POPULATE_LAYOUT.
CLEAR X_LAYOUT.
X_LAYOUT-ZEBRA = C_X.
X_LAYOUT-DETAIL_POPUP = C_X.
X_LAYOUT-DETAIL_INITIAL_LINES = C_X.
ENDFORM.
*& ---------------------------------------------------------*
*& Form OUTPUT_DATA_USING_ALV
*&----------------------------------------------------------*
* OUTPUT_DATA_USING_ALV
*& ---------------------------------------------------------*
FORM OUTPUT_DATA_USING_ALV.
PERFORM CALL_BLOCK_UNIT.
PERFORM APPEND_ITABS_TO_ALV_STRUC.
ENDFORM.
*& ---------------------------------------------------------*
*& Form CALL_BLOCK_UNIT
*&----------------------------------------------------------*
* CALL_BLOCK_UNIT
*& ---------------------------------------------------------*
FORM CALL_BLOCK_UNIT.
DATA: V_REPID LIKE SY-REPID.
V_REPID = SY-REPID.
CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_INIT'
EXPORTING
I_CALLBACK_PROGRAM = V_REPID.
ENDFORM.
*& ---------------------------------------------------------*
*& Form APPEND_ITABS_TO_ALV_STRUC
*&----------------------------------------------------------*
* APPEND_ITABS_TO_ALV_STRUC
*& ---------------------------------------------------------*
FORM APPEND_ITABS_TO_ALV_STRUC.
DATA: X_EVENTS TYPE SLIS_ALV_EVENT.
*- Append YAPTMAIN to ALV Structure.
IF NOT I_YAPTMAIN[] IS INITIAL.
*- Populate Field Catalogs Table.
CLEAR: I_FIELDCAT.
REFRESH: I_FIELDCAT.
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
I_STRUCTURE_NAME = C_TABLE
I_CLIENT_NEVER_DISPLAY = C_X
CHANGING
CT_FIELDCAT = I_FIELDCAT.
*- Populate Events Table.
CLEAR I_EVENTS.
REFRESH I_EVENTS.
CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
EXPORTING
I_LIST_TYPE = 0
IMPORTING
ET_EVENTS = I_EVENTS
EXCEPTIONS
LIST_TYPE_WRONG = 1
OTHERS = 2.
IF SY-SUBRC EQ C_0.
READ TABLE I_EVENTS WITH KEY NAME = C_TOP_OF_LIST INTO X_EVENTS.
IF SY-SUBRC EQ C_0.
MOVE C_TOP_OF_LIST_YAPTMAIN TO X_EVENTS-FORM.
MODIFY I_EVENTS FROM X_EVENTS INDEX SY-TABIX.
ENDIF.
ENDIF.
*- Call Function to append to ALV List.
CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'
EXPORTING
IS_LAYOUT = X_LAYOUT
IT_FIELDCAT = I_FIELDCAT
I_TABNAME = V_I_TAB
IT_EVENTS = I_EVENTS
TABLES
T_OUTTAB = I_YAPTMAIN
EXCEPTIONS
PROGRAM_ERROR = 1
MAXIMUM_OF_APPENDS_REACHED = 2
OTHERS = 3.
ENDIF.
*- Call ALV Function for List Display.
CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_DISPLAY'
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2.
ENDFORM.
*& ---------------------------------------------------------*
*& Form CLOSE_ARCHIVE_FILE
*&----------------------------------------------------------*
* CLOSE_ARCHIVE_FILE
*& ---------------------------------------------------------*
FORM CLOSE_ARCHIVE_FILE.
CALL FUNCTION 'ARCHIVE_CLOSE_FILE'
EXPORTING
ARCHIVE_HANDLE = V_READ_HANDLE
EXCEPTIONS
INTERNAL_ERROR = 1
WRONG_ACCESS_TO_ARCHIVE = 2
OTHERS = 3.
IF SY-SUBRC <> C_0.
MESSAGE I001 WITH 'Unable to close archive session'.
EXIT.
ENDIF.
ENDFORM.
*& ---------------------------------------------------------*
*& Form TOP_OF_LIST
*&----------------------------------------------------------*
* TOP_OF_LIST
*& ---------------------------------------------------------*
FORM TOP_OF_LIST_YAPTMAIN.
WRITE: /30 C_TEXT5.
ULINE.
WRITE: /.
WRITE: / C_TEXT6.
ENDFORM.
*& ---------------------------------------------------------*
*& Form GET_SELECTION_TEXTS
*&----------------------------------------------------------*
* GET_SELECTION_TEXTS
*& ---------------------------------------------------------*
FORM GET_SELECTION_TEXTS.
V_TEST = C_TEXT7.
ENDFORM.