* _ _ _ _ _ * /_\ | |__ __ _ _ __ ___ __ _ __| | __ _| |__ _ __ /_\ * //_\\| '_ \ / _` | '_ \ / __/ _` |/ _` |/ _` | '_ \| '__//_\\ * / _ \ |_) | (_| | |_) | (_| (_| | (_| | (_| | |_) | | / _ \ * \_/ \_/_.__/ \__,_| .__/ \___\__,_|\__,_|\__,_|_.__/|_| \_/ \_/ * |_| www.abapcadabra.com *---------------------------------------------------------------------------- * program : ZABAPCADABRA_DUMP_REMOVER * title : Dump overview - delete dumps * functional area : Cross modules * environment : 4.7 * program Function : This report shows dumps, much like ST22, and allows you to * remove a dump, like report RSSNAPDL does. * Documentation : Search for "Dump remover" on AbapcadabrA.com * Installation : Apply this source code and generate. * Previous version : This is the initial version * Developer name : Wim Maasdam * Development date : 30/11/2017 * Version : 0.1 *--------------------------------------------------------------------- * Change list: * Date Description * 30/11/2017 Initial release *--------------------------------------------------------------------- REPORT ZABAPCADABRA_REMOVE_SNAP. tables: sscrfields. "Selection screen purpose only TYPE-POOLS SABC. CLASS lcl_event_manager DEFINITION. PUBLIC SECTION. METHODS: constructor IMPORTING r_object TYPE REF TO cl_salv_table, on_link_click FOR EVENT link_click OF cl_salv_events_table IMPORTING row column. PRIVATE SECTION. DATA: go_salv TYPE REF TO cl_salv_table. ENDCLASS. CLASS LCL_controller DEFINITION. PUBLIC SECTION. TYPES: begin of ty_alv_report, DATUM type SNAP-DATUM, UZEIT type SNAP-UZEIT, AHOST type SNAP-AHOST, UNAME type SNAP-UNAME, MANDT type SNAP-MANDT, MODNO type SNAP-MODNO, SEQNO type SNAP-SEQNO, XHOLD type SNAP-XHOLD, DUMPTXT type C length 40, REPORT type sy-repid, delete_icon type icon-id, size type c length 15, * Color settings COLORS TYPE lvc_t_scol, end of ty_alv_report. CLASS-DATA: gt_alv_data type standard table of ty_alv_report, go_alv TYPE REF TO cl_salv_table, go_event_man TYPE REF TO lcl_event_manager. CLASS-METHODS: alv_report. ENDCLASS. *--------------------------------------------------------------------- * C L A S S D E F I N I T I O N S *--------------------------------------------------------------------- CLASS lcl_dump_utility DEFINITION. PUBLIC SECTION. TYPES: begin of ty_SNAP, DATUM type SNAP-DATUM, UZEIT type SNAP-UZEIT, AHOST type SNAP-AHOST, UNAME type SNAP-UNAME, MANDT type SNAP-MANDT, MODNO type SNAP-MODNO, SEQNO type SNAP-SEQNO, XHOLD type SNAP-XHOLD, FLIST type SNAP-FLIST, COUNT type sy-dbcnt, end of ty_SNAP. CLASS-DATA: gt_DUMPLIST type standard table of ty_SNAP, gr_selection_date type range of sy-datum, gr_selection_users type range of sy-uname, gv_administrator_user type boolean value abap_false. CLASS-METHODS: dump_select. ENDCLASS. CLASS lcl_dump_utility IMPLEMENTATION. METHOD dump_select. data: lw_SNAP type ty_snap. select DATUM UZEIT AHOST UNAME MANDT MODNO SEQNO XHOLD FLIST from SNAP into table GT_DUMPLIST where datum in gr_SELECTION_DATE and uname in gr_selection_users and SEQNO = '000'. * To determine the size of the dump - select the number of SNAP entries it occupies: loop at GT_DUMPLIST into lw_snap. select count( DISTINCT SEQNO ) from SNAP into lw_snap-count where datum = lw_snap-datum and uzeit = lw_snap-uzeit and ahost = lw_snap-ahost and uname = lw_snap-uname and mandt = lw_snap-mandt and modno = lw_snap-modno. modify GT_DUMPLIST from lw_snap transporting count. endloop. ENDMETHOD. ENDCLASS. CLASS lcl_event_manager IMPLEMENTATION. METHOD constructor. DATA: lo_events TYPE REF TO cl_salv_events_table. go_salv = r_object. lo_events = go_salv->get_event( ). * SET HANDLER on_user_command FOR lo_events. SET HANDLER on_link_click FOR lo_events. ENDMETHOD. "constructor METHOD on_link_click. DATA: lw_ALV_data type lcl_controller=>ty_ALV_report. READ TABLE lcl_controller=>gt_ALV_data INTO lw_ALV_data INDEX row. IF sy-subrc = 0. CASE column. WHEN 'DELETE_ICON'. if lw_ALV_data-delete_icon = ICON_DELETE. if lw_ALV_data-xhold = 'X'. message 'This dump has been marked as - hold - ' type 'S'. else. * PERFORM THE ACTUAL DELETION: A DUMP LIVES IN THE SNAP TABLE: DELETE FROM snap WHERE datum = lw_ALV_data-datum AND uzeit = lw_ALV_data-uzeit AND ahost = lw_ALV_data-ahost AND uname = lw_ALV_data-uname AND mandt = lw_ALV_data-mandt AND modno = lw_ALV_data-modno. if sy-subrc = 0. message 'Dump was removed' type 'S'. COMMIT WORK AND WAIT. delete lcl_controller=>gt_ALV_data index row. go_salv->refresh( ). else. message 'Dump could not be removed' type 'S'. endif. endif. endif. ENDCASE. ENDIF. ENDMETHOD. ENDCLASS. CLASS lcl_controller IMPLEMENTATION. method alv_report. DATA: lv_text TYPE scrtext_s, lv_text_m TYPE scrtext_m, lv_text_l TYPE scrtext_l, rf_functions_list TYPE REF TO cl_salv_functions_list, rf_columns_table TYPE REF TO cl_salv_columns_table, rf_column_table TYPE REF TO cl_salv_column_table, rf_column TYPE REF TO cl_salv_column, lw_alv_data type ty_alv_report, lw_DUMP type lcl_DUMP_utility=>ty_SNAP, * Aggregation settings: lo_aggregations TYPE REF TO cl_salv_aggregations, * The header/footer box rf_alv_header TYPE REF TO cl_salv_form_layout_grid, rf_alv_footer TYPE REF TO cl_salv_form_layout_grid, rf_sorts TYPE REF TO cl_salv_sorts, lw_colored_field TYPE lvc_s_scol, lw_colored_status TYPE lvc_s_scol, lt_COLORS TYPE lvc_t_scol, lv_fieldname TYPE string, begin of lw_tag, code type c length 2, length type n length 3, end of lw_tag. FIELD-SYMBOLS type any. DEFINE set_text_field. * rf_column ?= rf_columns_table->get_column( &1 ). move rf_columns_table->get_column( &1 ) to rf_column. lv_text = &2. lv_text_m = &2. lv_text_l = &2. rf_column->set_short_text( lv_text ). rf_column->set_medium_text( lv_text_m ). rf_column->set_long_text( lv_text_l ). rf_column->set_zero( abap_false ). END-OF-DEFINITION. DEFINE set_hidden_field. set_text_field &1 &2. rf_column->set_visible( abap_false ). END-OF-DEFINITION. clear: gt_alv_data[]. loop at lcl_dump_utility=>gt_DUMPLIST into lw_DUMP. clear: lw_alv_data, lw_alv_data-colors[]. move-corresponding lw_DUMP to lw_alv_data. lw_tag = lw_DUMP-FLIST(5). shift lw_DUMP-FLIST left by 5 places. lw_alv_data-dumptxt = lw_DUMP-FLIST(lw_tag-length). shift lw_DUMP-FLIST left by lw_tag-length places. lw_tag = lw_DUMP-FLIST(5). shift lw_DUMP-FLIST left by 5 places. lw_alv_data-report = lw_DUMP-FLIST(lw_tag-length). if lw_DUMP-UNAME = sy-UNAME or "Only allow deleting own dumps lcl_dump_utility=>gv_administrator_user = abap_true. lw_alv_data-delete_icon = ICON_DELETE. else. lw_alv_data-delete_icon = ICON_SPACE. endif. * Set the color of the user ID: if lw_alv_data-uname = sy-uname. lw_colored_field-color-col = 7. lw_colored_field-color-int = 0. lw_colored_field-color-inv = 0. lw_colored_field-FNAME = 'UNAME'. append lw_colored_field to lw_alv_data-colors[]. endif. lw_DUMP-count = lw_DUMP-count * 1675 * 2. "Size of all fields on SNAP, as double bytes. divide lw_DUMP-count by 1000. write lw_DUMP-count to lw_alv_data-size LEFT-JUSTIFIED. concatenate lw_alv_data-size 'kb' into lw_alv_data-size. append lw_alv_data to GT_ALV_DATA . endloop. try. cl_salv_table=>factory( importing r_salv_table = go_alv changing t_table = gt_alv_data ). rf_functions_list = go_alv->get_functions( ). rf_functions_list->set_all( ). rf_columns_table = go_alv->get_columns( ). rf_columns_table->set_color_column( value = 'COLORS' ). rf_columns_table->set_optimize( abap_true ). "Always a good idea set_hidden_field: 'SEQNO' ''. set_text_field: 'DUMPTXT' 'Runtime error', 'REPORT' 'Abap program', 'DELETE_ICON' '___', 'SIZE' 'Size'. * Button field rf_column_table ?= rf_columns_table->get_column( 'DELETE_ICON' ). rf_column_table->set_cell_type( if_salv_c_cell_type=>HOTSPOT ). CREATE OBJECT go_event_man EXPORTING r_object = go_alv. go_alv->display( ). catch CX_SALV_MSG CX_SALV_DATA_ERROR CX_SALV_NOT_FOUND CX_SALV_EXISTING. message 'ALV error' type 'S'. endtry. endmethod. ENDCLASS. *--------------------------------------------------------------------- * S E L E C T I O N - S C R E E N *--------------------------------------------------------------------- selection-SCREEN BEGIN OF LINE. selection-SCREEN COMMENT 1(13) lbl_01 FOR FIELD so_date. select-options so_date for sy-datum default sy-datum. selection-SCREEN END OF LINE. selection-SCREEN BEGIN OF LINE. selection-SCREEN COMMENT 1(13) lbl_02 FOR FIELD so_uname. select-options so_uname for sy-uname default sy-uname. selection-SCREEN END OF LINE. AT SELECTION-SCREEN. case sy-ucomm. when 'ADMIN'. message 'Welcome administrator' type 'S'. lcl_dump_utility=>gv_administrator_user = abap_true. endcase. *--------------------------------------------------------------------- * I N I T I A L I Z A T I O N *--------------------------------------------------------------------- INITIALIZATION. * All texts for this report have been set up as hard-coded texts lbl_01 = 'Date'. lbl_02 = 'User'. *--------------------------------------------------------------------- * S T A R T - O F - S E L E C T I O N *--------------------------------------------------------------------- START-OF-SELECTION. lcl_dump_utility=>gr_selection_date[] = so_date[]. lcl_dump_utility=>gr_selection_users[] = so_uname[]. lcl_dump_utility=>dump_select( ). lcl_controller=>alv_report( ).