Step-by-step procedure for Creation of Custom Archiving Object

Click here for the tutorial

REPORT ZCUSARCH_DELETE .

SELECTION-SCREEN BEGIN OF BLOCK sel_prog WITH FRAME TITLE text-001.
PARAMETERS: p_test AS CHECKBOX DEFAULT 'X'.
SELECTION-SCREEN END OF BLOCK sel_prog.

* Data definition
DATA: gv_test(1) TYPE c,
gv_prot(1) TYPE c,
gv_arc_hand TYPE sy-tabix,
gv_commit_count TYPE arch_usr-arch_comit,
gt_zcus TYPE TABLE OF ztestarch,
gv_rec_count TYPE i,
gv_rec_tot TYPE i,
gt_arch_stat TYPE TABLE OF arch_stat,
gv_count_del TYPE i,
gs_zcus TYPE ztestarch,
gs_zcus_del TYPE ztestarch,
gt_zcus_del TYPE TABLE OF ztestarch,
gs_arch_stat TYPE arch_stat.

* Start of selection
START-OF-SELECTION.


* set runtime parameters

IF NOT p_test IS INITIAL.
gv_test = 'X'.
ENDIF.

CLEAR gv_commit_count.

* Open archive file

CALL FUNCTION 'ARCHIVE_OPEN_FOR_DELETE'
EXPORTING
object = 'ZCUSARCH'
test_mode = gv_test
IMPORTING
archive_handle = gv_arc_hand
EXCEPTIONS
file_already_open = 1
file_io_error = 2
internal_error = 3
no_file_available = 4
object_not_found = 5
open_error = 6
not_authorized = 7.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.

CALL FUNCTION 'ARCHIVE_GET_CUSTOMIZING_DATA'
EXPORTING
object = 'ZCUSARCH'
IMPORTING
commit_count_for_delete_prg = gv_commit_count.

DO.
CALL FUNCTION 'ARCHIVE_GET_NEXT_OBJECT'
EXPORTING
archive_handle = gv_arc_hand
EXCEPTIONS
end_of_file = 1.
IF sy-subrc <> 0.
EXIT.
ENDIF.

CALL FUNCTION 'ARCHIVE_GET_TABLE'
EXPORTING
archive_handle = gv_arc_hand
record_structure = 'ZTESTARCH'
all_records_of_object = 'X'
TABLES
table = gt_zcus.

IF gv_rec_count = gv_commit_count.
PERFORM delete_data.
gv_rec_count = 0.
ENDIF.
ENDDO.
IF gv_rec_count > 0.
PERFORM delete_data.
ENDIF.

WRITE:/ sy-uline.
WRITE:/ text-008, gv_rec_tot.
WRITE:/ text-009, gv_count_del.

* create protocol

CLEAR gs_arch_stat-tabname.
INSERT gs_arch_stat INTO gt_arch_stat INDEX 1.

CALL FUNCTION 'ARCHIVE_GIVE_STATISTICS'
EXPORTING
archive_handle = gv_arc_hand
TABLES
table = gt_arch_stat.

CALL FUNCTION 'ARCHIVE_WRITE_STATISTICS'
EXPORTING
archive_handle = gv_arc_hand.

CALL FUNCTION 'ARCHIVE_CLOSE_FILE'
EXPORTING
archive_handle = gv_arc_hand.


*&---------------------------------------------------------------------*
*& Form delete_data
*&---------------------------------------------------------------------*
* delete archived entries from ZMATK
*----------------------------------------------------------------------*
FORM delete_data.

LOOP AT gt_zcus_del INTO gs_zcus_del.
IF gv_test IS INITIAL.

DELETE FROM ztestarch
WHERE vbeln = gs_zcus_del-vbeln.
gv_count_del = gv_count_del + sy-dbcnt.
ENDIF.
ENDLOOP.
COMMIT WORK.
REFRESH gt_zcus_del.
ENDFORM. "delete_data

Please send us your feedback/suggestions at webmaster@SAPTechnical.COM 

HomeContribute About Us Privacy Terms Of Use • Disclaimer • SafeCompanies: Advertise on SAPTechnical.COM | Post JobContact Us  

Graphic Design by Round the Bend Wizards

footer image footer image