Program to check how many times a Z* object is used in the system. The objects are:
It can be used to identify useless objects to be deleted
REPORT ztool_whereused.
TABLES: dd04l,
dd01l,
dd02l,
dd40l.
SELECTION-SCREEN BEGIN OF BLOCK selection WITH FRAME TITLE TEXT-001.
SELECT-OPTIONS: as4user FOR dd04l-as4user NO INTERVALS,
rname FOR dd04l-rollname NO INTERVALS MODIF ID rnm,
dname FOR dd01l-domname NO INTERVALS MODIF ID dnm,
tname FOR dd02l-tabname NO INTERVALS MODIF ID tnm,
ttname FOR dd40l-typename NO INTERVALS MODIF ID ttn.
PARAMETERS: p_null AS CHECKBOX DEFAULT abap_false.
SELECTION-SCREEN END OF BLOCK selection.
SELECTION-SCREEN BEGIN OF BLOCK options WITH FRAME TITLE TEXT-002.
PARAMETERS: r_table RADIOBUTTON GROUP r1 DEFAULT 'X' USER-COMMAND u,
r_types RADIOBUTTON GROUP r1,
r_struc RADIOBUTTON GROUP r1,
r_datel RADIOBUTTON GROUP r1,
r_domin RADIOBUTTON GROUP r1.
SELECTION-SCREEN END OF BLOCK options.
INITIALIZATION.
as4user[] = VALUE #( ( sign = rsmds_c_sign-excluding
option = rsmds_c_option-equal
low = 'SAP' ) ).
rname[] = VALUE #( ( sign = rsmds_c_sign-including
option = rsmds_c_option-contains_pattern
low = 'Z*' ) ).
dname[] = VALUE #( ( sign = rsmds_c_sign-including
option = rsmds_c_option-contains_pattern
low = 'Z*' ) ).
tname[] = VALUE #( ( sign = rsmds_c_sign-including
option = rsmds_c_option-contains_pattern
low = 'Z*' ) ).
ttname[] = VALUE #( ( sign = rsmds_c_sign-including
option = rsmds_c_option-contains_pattern
low = 'Z*' ) ).
AT SELECTION-SCREEN OUTPUT.
LOOP AT SCREEN.
CASE screen-group1.
WHEN 'RNM'.
CHECK r_datel = abap_false.
screen-active = '0'.
MODIFY SCREEN.
WHEN 'DNM'.
CHECK r_domin = abap_false.
screen-active = '0'.
MODIFY SCREEN.
WHEN 'TNM'.
CHECK r_table = abap_false AND r_struc = abap_false.
screen-active = '0'.
MODIFY SCREEN.
WHEN 'TTN'.
CHECK r_types = abap_false.
screen-active = '0'.
MODIFY SCREEN.
ENDCASE.
ENDLOOP.
START-OF-SELECTION.
DATA: BEGIN OF t_out OCCURS 0,
rollname TYPE ddobjname,
lines TYPE /sapapo/rsp_quant,
END OF t_out.
DATA: type TYPE seu_obj,
s_find TYPE rsfind,
t_find TYPE TABLE OF rsfind,
t_usages TYPE TABLE OF rsfindlst,
t_scope TYPE STANDARD TABLE OF seu_obj,
t_fieldcat TYPE slis_t_fieldcat_alv.
* Data Elements
IF r_datel = abap_true.
type = 'DE'.
SELECT rollname FROM dd04l INTO TABLE @DATA(t_data) WHERE rollname IN @rname[] AND as4user IN @as4user[].
ENDIF.
* Domains
IF r_domin = abap_true.
type = 'DD'.
SELECT domname FROM dd01l INTO TABLE t_data WHERE domname IN dname AND as4user IN as4user[].
ENDIF.
* Structures
IF r_struc = abap_true.
type = 'DS'.
SELECT tabname FROM dd02l INTO TABLE t_data WHERE tabname IN tname AND tabclass = 'INTTAB' AND as4user IN as4user[].
ENDIF.
* Tables
IF r_table = abap_true.
type = 'DT'.
SELECT tabname FROM dd02l INTO TABLE t_data WHERE tabname IN tname AND tabclass = 'TRANSP' AND as4user IN as4user[].
ENDIF.
* Table Types
IF r_types = abap_true.
type = 'DA'.
SELECT typename FROM dd40l INTO TABLE t_data WHERE typename IN ttname AND as4user IN as4user[].
ENDIF.
* Cross Scope Types
CALL FUNCTION 'REPOSITORY_CROSS_SCOPE_TYPES'
EXPORTING
object_type = type
TABLES
scope_object_cls = t_scope
EXCEPTIONS
no_cross_for_this_object = 0
wrong_type = 0
OTHERS = 0.
* For each object
LOOP AT t_data INTO DATA(s_data).
CLEAR t_find.
t_find = VALUE #( ( object = s_data-rollname ) ).
* Search where is used this object.
CALL FUNCTION 'RS_EU_CROSSREF'
EXPORTING
i_find_obj_cls = type
i_answer = 'J'
no_dialog = abap_true
without_text = abap_true
with_generated_objects = abap_true
TABLES
i_findstrings = t_find
o_founds = t_usages
i_scope_object_cls = t_scope
EXCEPTIONS
OTHERS = 0.
CHECK p_null IS INITIAL OR ( p_null IS NOT INITIAL AND t_usages[] IS INITIAL ).
t_out-rollname = s_data-rollname.
t_out-lines = lines( t_usages ).
APPEND t_out TO t_out.
ENDLOOP.
SORT t_out[] BY lines ASCENDING.
* ALV
CALL METHOD cl_salv_table=>factory
IMPORTING
r_salv_table = DATA(gr_table)
CHANGING
t_table = t_out[].
CHECK gr_table IS BOUND.
*Optimize collums
DATA(lo_cols) = gr_table->get_columns( ).
lo_cols->set_optimize( abap_true ).
*Show Buttons
DATA(lr_functions) = gr_table->get_functions( ).
lr_functions->set_all( abap_true ).
*Display
gr_table->display( ).