Hello!,
This report find all unused object by packages and delete.
Hope this helps! 😃
*&---------------------------------------------------------------------*
*& Report ZSEARCH_OBJ
*&
*&---------------------------------------------------------------------*
REPORT zsearch_obj.
*----------------------------------------------------------------------*
* data definition
*----------------------------------------------------------------------*
* Batchinputdata of single transaction
DATA: bdcdata LIKE bdcdata OCCURS 0 WITH HEADER LINE.
* messages of call transaction
DATA: messtab LIKE bdcmsgcoll OCCURS 0 WITH HEADER LINE.
* error session opened (' ' or 'X')
DATA: e_group_opened.
*----------------------------------------------------------------------*
* selection screen
*----------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF LINE.
PARAMETERS cupdate LIKE ctu_params-updmode DEFAULT 'L' NO-DISPLAY.
"S: synchronously
"A: asynchronously
"L: local
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF BLOCK b01.
PARAMETERS ctumode LIKE ctu_params-dismode DEFAULT 'N'.
"A: show all dynpros
"E: show dynpro on error only
"N: do not display dynpro
PARAMETERS p_objt TYPE devclass DEFAULT 'Z'.
TYPES:
BEGIN OF tp_object,
prognam TYPE c LENGTH 30,
utilized TYPE c LENGTH 20,
subrc LIKE sy-subrc,
END OF tp_object.
SELECTION-SCREEN END OF BLOCK b01.
START-OF-SELECTION.
DATA l_subrc LIKE sy-subrc.
DATA l_answer VALUE '0'.
DATA lt_tadir TYPE TABLE OF tadir WITH HEADER LINE.
DATA lt_prog TYPE TABLE OF tp_object WITH HEADER LINE.
SELECT * FROM tadir
INTO TABLE lt_tadir
WHERE devclass = p_objt.
LOOP AT lt_tadir.
CLEAR: l_subrc, lt_prog.
CASE lt_tadir-object.
WHEN 'TABL'.
IF lt_tadir-cproject = 'S'.
PERFORM f_exec_obj
USING lt_tadir-obj_name
CHANGING l_subrc.
ELSE.
PERFORM f_exec_tab
USING lt_tadir-obj_name
CHANGING l_subrc.
ENDIF.
WHEN OTHERS.
IF lt_tadir-cproject = 'S'.
PERFORM f_exec_obj
USING lt_tadir-obj_name
CHANGING l_subrc.
ELSE.
PERFORM f_exec_tab
USING lt_tadir-obj_name
CHANGING l_subrc.
ENDIF.
ENDCASE.
lt_prog-prognam = lt_tadir-obj_name.
lt_prog-subrc = l_subrc.
IF l_subrc EQ 0.
lt_prog-utilized = 'NO FOUND'.
ELSE.
lt_prog-utilized = 'FOUND'.
ENDIF.
APPEND lt_prog.
ENDLOOP.
PERFORM f_popup_question
USING 'Delete objects?'
CHANGING l_answer.
LOOP AT lt_prog WHERE subrc EQ 0.
IF l_answer EQ 1.
PERFORM f_exec_dele
USING lt_prog-prognam.
ENDIF.
WRITE: / lt_prog-prognam, ' ',
lt_prog-subrc, ' ',
lt_prog-utilized.
ENDLOOP.
PERFORM close_group.
*&---------------------------------------------------------------------*
*& Form f_popup_question
*&---------------------------------------------------------------------*
FORM f_popup_question
USING p_question TYPE c
CHANGING p_answer TYPE c.
CALL FUNCTION 'POPUP_TO_CONFIRM'
EXPORTING
text_question = p_question
start_column = 15
start_row = 6
IMPORTING
answer = p_answer
EXCEPTIONS
text_not_found = 1
OTHERS = 2.
IF sy-subrc NE 0.
MESSAGE ID sy-msgid TYPE 'I' NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
ENDFORM. "f_popup_question
*&---------------------------------------------------------------------*
*& Form f_exec_TRAN
*&---------------------------------------------------------------------*
FORM f_exec_tab
USING p_obj TYPE c
CHANGING c_subrc LIKE sy-subrc.
PERFORM bdc_dynpro USING 'SAPMSRD0' '0102'.
PERFORM bdc_field USING 'BDC_CURSOR' 'RSRD1-DDTYPE_VAL'.
PERFORM bdc_field USING 'BDC_OKCODE' '=CREF'.
PERFORM bdc_field USING 'RSRD1-DDTYPE' 'X'.
PERFORM bdc_field USING 'RSRD1-DDTYPE_VAL' p_obj.
PERFORM bdc_dynpro USING 'SAPICDA_' '0101'.
PERFORM bdc_field USING 'BDC_CURSOR' 'RSEUV-TDFIND'.
PERFORM bdc_field USING 'BDC_OKCODE' '=MARK'.
PERFORM bdc_field USING 'RSEUX-CP' 'X'.
PERFORM bdc_field USING 'RSEUX-CO' 'X'.
PERFORM bdc_field USING 'RSEUX-CYT' 'X'.
PERFORM bdc_dynpro USING 'SAPICDA_' '0101'.
PERFORM bdc_field USING 'BDC_CURSOR' 'RSEUV-TDFIND'.
PERFORM bdc_field USING 'BDC_OKCODE' '=ENTR'.
PERFORM bdc_field USING 'RSEUX-CP' 'X'.
PERFORM bdc_field USING 'RSEUX-CO' 'X'.
PERFORM bdc_field USING 'RSEUX-CYT' 'X'.
PERFORM bdc_field USING 'RSEUX-CWO' 'X'.
PERFORM bdc_field USING 'RSEUX-CFF' 'X'.
PERFORM bdc_field USING 'RSEUX-C3I' 'X'.
PERFORM bdc_field USING 'RSEUX-CKI' 'X'.
PERFORM bdc_field USING 'RSEUX-CDE' 'X'.
PERFORM bdc_field USING 'RSEUX-CDA' 'X'.
PERFORM bdc_field USING 'RSEUX-CDTF' 'X'.
PERFORM bdc_field USING 'RSEUX-CDSF' 'X'.
PERFORM bdc_field USING 'RSEUX-CGE' 'X'.
PERFORM bdc_field USING 'RSEUX-CGD' 'X'.
PERFORM bdc_dynpro USING 'SAPLSPO1' '0100'.
PERFORM bdc_field USING 'BDC_OKCODE' '=YES'.
PERFORM bdc_dynpro USING 'SAPMSRD0' '0102'.
PERFORM bdc_field USING 'BDC_CURSOR' 'RSRD1-DDTYPE_VAL'.
PERFORM bdc_field USING 'BDC_OKCODE' '=BACK'.
PERFORM bdc_field USING 'RSRD1-DDTYPE' 'X'.
PERFORM bdc_field USING 'RSRD1-DDTYPE_VAL' p_obj.
CALL TRANSACTION 'SE11' USING bdcdata
MODE ctumode
UPDATE cupdate
MESSAGES INTO messtab.
c_subrc = sy-subrc.
REFRESH bdcdata.
ENDFORM. " f_exec_TRAN
*&---------------------------------------------------------------------*
*& Form F_EXEC_OBJ
*&---------------------------------------------------------------------*
FORM f_exec_obj USING p_obj TYPE c
CHANGING c_subrc LIKE sy-subrc.
PERFORM bdc_dynpro USING 'SAPMSRD0' '0102'.
PERFORM bdc_field USING 'BDC_CURSOR' 'RSRD1-DDTYPE_VAL'.
PERFORM bdc_field USING 'BDC_OKCODE' '=CREF'.
PERFORM bdc_field USING 'RSRD1-TBMA_VAL' 'TADIR'.
PERFORM bdc_field USING 'RSRD1-DDTYPE' 'X'.
PERFORM bdc_field USING 'RSRD1-DDTYPE_VAL' p_obj.
PERFORM bdc_dynpro USING 'SAPICDE_' '0101'.
PERFORM bdc_field USING 'BDC_CURSOR' 'RSEUV-TDFIND'.
PERFORM bdc_field USING 'BDC_OKCODE' '=MARK'.
PERFORM bdc_field USING 'RSEUX-CDTF' 'X'.
PERFORM bdc_dynpro USING 'SAPICDE_' '0101'.
PERFORM bdc_field USING 'BDC_CURSOR' 'RSEUV-TDFIND'.
PERFORM bdc_field USING 'BDC_OKCODE' '=ENTR'.
PERFORM bdc_field USING 'RSEUX-CDTF' 'X'.
PERFORM bdc_field USING 'RSEUX-CDSF' 'X'.
PERFORM bdc_field USING 'RSEUX-CDVF' 'X'.
PERFORM bdc_field USING 'RSEUX-CDA' 'X'.
PERFORM bdc_field USING 'RSEUX-CDH' 'X'.
PERFORM bdc_field USING 'RSEUX-CDE' 'X'.
PERFORM bdc_field USING 'RSEUX-CMEA' 'X'.
PERFORM bdc_field USING 'RSEUX-CP' 'X'.
PERFORM bdc_field USING 'RSEUX-CO' 'X'.
PERFORM bdc_field USING 'RSEUX-CYT' 'X'.
PERFORM bdc_field USING 'RSEUX-CWO' 'X'.
PERFORM bdc_field USING 'RSEUX-CFF' 'X'.
PERFORM bdc_field USING 'RSEUX-C3I' 'X'.
PERFORM bdc_field USING 'RSEUX-CKI' 'X'.
PERFORM bdc_field USING 'RSEUX-CGE' 'X'.
PERFORM bdc_field USING 'RSEUX-CGD' 'X'.
PERFORM bdc_dynpro USING 'SAPMSRD0' '0102'.
PERFORM bdc_field USING 'BDC_CURSOR' 'RSRD1-DDTYPE_VAL'.
PERFORM bdc_field USING 'BDC_OKCODE' '=BACK'.
PERFORM bdc_field USING 'RSRD1-TBMA_VAL' 'TADIR'.
PERFORM bdc_field USING 'RSRD1-DDTYPE' 'X'.
PERFORM bdc_field USING 'RSRD1-DDTYPE_VAL' p_obj.
CALL TRANSACTION 'SE11' USING bdcdata
MODE ctumode
UPDATE cupdate
MESSAGES INTO messtab.
c_subrc = sy-subrc.
REFRESH bdcdata.
ENDFORM. "F_EXEC_OBJ
*----------------------------------------------------------------------*
* end batchinput session *
* (call transaction using...: error session) *
*----------------------------------------------------------------------*
FORM close_group.
IF e_group_opened = 'X'.
CALL FUNCTION 'BDC_CLOSE_GROUP'.
WRITE: /.
WRITE: /(30) 'Fehlermappe wurde erzeugt'(i06).
e_group_opened = ' '.
ENDIF.
* ENDIF.
ENDFORM. "CLOSE_GROUP
*----------------------------------------------------------------------*
* Start new screen *
*----------------------------------------------------------------------*
FORM bdc_dynpro USING program dynpro.
CLEAR bdcdata.
bdcdata-program = program.
bdcdata-dynpro = dynpro.
bdcdata-dynbegin = 'X'.
APPEND bdcdata.
ENDFORM. "BDC_DYNPRO
*----------------------------------------------------------------------*
* Insert field *
*----------------------------------------------------------------------*
FORM bdc_field USING fnam fval.
IF fval <> '/'.
CLEAR bdcdata.
bdcdata-fnam = fnam.
bdcdata-fval = fval.
APPEND bdcdata.
ENDIF.
ENDFORM. "BDC_FIELD
*&---------------------------------------------------------------------*
*& Form F_EXEC_DELE
*&---------------------------------------------------------------------*
FORM f_exec_dele USING p_obj TYPE c.
PERFORM bdc_dynpro USING 'SAPMSRD0' '0102'.
PERFORM bdc_field USING 'BDC_CURSOR' 'RSRD1-DDTYPE_VAL'.
PERFORM bdc_field USING 'BDC_OKCODE' '=DELE'.
PERFORM bdc_field USING 'RSRD1-DDTYPE' 'X'.
PERFORM bdc_field USING 'RSRD1-DDTYPE_VAL' p_obj.
PERFORM bdc_dynpro USING 'SAPLSPO1' '0100'.
PERFORM bdc_field USING 'BDC_OKCODE' '=YES'.
PERFORM bdc_dynpro USING 'SAPMSRD0' '0102'.
PERFORM bdc_field USING 'BDC_CURSOR' 'RSRD1-DDTYPE_VAL'.
PERFORM bdc_field USING 'BDC_OKCODE' '=BACK'.
PERFORM bdc_field USING 'RSRD1-DDTYPE' 'X'.
PERFORM bdc_field USING 'RSRD1-DDTYPE_VAL' p_obj.
CALL TRANSACTION 'SE11'
USING bdcdata
MODE ctumode
UPDATE cupdate
MESSAGES INTO messtab.
ENDFORM. " F_EXEC_DELE