From c542694a45227386e8784b4ccfc4b40d138cc362 Mon Sep 17 00:00:00 2001 From: Ali Bayest <65496394+Alih-b@users.noreply.github.com> Date: Tue, 16 Apr 2024 19:14:42 +0330 Subject: [PATCH 1/5] worked on #12 --- src/#mbtools#cl_command__show.clas.abap | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/src/#mbtools#cl_command__show.clas.abap b/src/#mbtools#cl_command__show.clas.abap index a60a186..d0dc5b0 100644 --- a/src/#mbtools#cl_command__show.clas.abap +++ b/src/#mbtools#cl_command__show.clas.abap @@ -165,13 +165,32 @@ CLASS /mbtools/cl_command__show IMPLEMENTATION. report_structure = ls_report EXCEPTIONS no_report_transaction = 1 - OTHERS = 2. + others = 2. IF sy-subrc = 0 AND ls_report-report IS NOT INITIAL. rs_tadir_key-object = 'PROG'. - rs_tadir_key-obj_name = ls_report-report. + CASE ls_report-reporttype. + WHEN INITIAL. + rs_tadir_key-obj_name = ls_report-report. + WHEN 'TR'. + " It is very unlikely to have a parameter t-code for + " another parameter t-code + " and SAP discourages it with warning + " so this is sufficient + lv_tcode = ls_report-report. + CALL FUNCTION 'SRT_GET_REPORT_OF_TCODE' + EXPORTING + tcode = lv_tcode + IMPORTING + report_structure = ls_report + EXCEPTIONS + no_report_transaction = 1 + others = 2. + + rs_tadir_key-obj_name = ls_report-report. + WHEN OTHERS. + ENDCASE. RETURN. ENDIF. - " Parameter Transaction SELECT SINGLE param INTO lv_param FROM tstcp WHERE tcode = lv_tcode. IF sy-subrc <> 0. From 1a93b9aebc9ef6717c67c2ae2c1b1d9d51a017ea Mon Sep 17 00:00:00 2001 From: Ali Bayest <65496394+Alih-b@users.noreply.github.com> Date: Wed, 17 Apr 2024 10:47:30 +0330 Subject: [PATCH 2/5] #12 added support for more types of parameter t-codes --- src/#mbtools#cl_command__show.clas.abap | 55 ++++++++++++++++++------- 1 file changed, 40 insertions(+), 15 deletions(-) diff --git a/src/#mbtools#cl_command__show.clas.abap b/src/#mbtools#cl_command__show.clas.abap index d0dc5b0..6ce9b86 100644 --- a/src/#mbtools#cl_command__show.clas.abap +++ b/src/#mbtools#cl_command__show.clas.abap @@ -151,6 +151,7 @@ CLASS /mbtools/cl_command__show IMPLEMENTATION. lt_param TYPE string_table, ls_report TYPE srepovari, ls_mtdkey TYPE seocpdkey, + lv_object_is_tcode TYPE abap_bool, lv_object TYPE c LENGTH 120. lv_tcode = iv_object_name. @@ -165,29 +166,30 @@ CLASS /mbtools/cl_command__show IMPLEMENTATION. report_structure = ls_report EXCEPTIONS no_report_transaction = 1 - others = 2. + OTHERS = 2. IF sy-subrc = 0 AND ls_report-report IS NOT INITIAL. rs_tadir_key-object = 'PROG'. CASE ls_report-reporttype. - WHEN INITIAL. + WHEN ''. rs_tadir_key-obj_name = ls_report-report. WHEN 'TR'. " It is very unlikely to have a parameter t-code for " another parameter t-code " and SAP discourages it with warning " so this is sufficient - lv_tcode = ls_report-report. - CALL FUNCTION 'SRT_GET_REPORT_OF_TCODE' - EXPORTING - tcode = lv_tcode - IMPORTING - report_structure = ls_report - EXCEPTIONS - no_report_transaction = 1 - others = 2. - + lv_tcode = ls_report-report. + CALL FUNCTION 'SRT_GET_REPORT_OF_TCODE' + EXPORTING + tcode = lv_tcode + IMPORTING + report_structure = ls_report + EXCEPTIONS + no_report_transaction = 1 + OTHERS = 2. rs_tadir_key-obj_name = ls_report-report. - WHEN OTHERS. + WHEN OTHERS. + MESSAGE 'It is a generated report' type 'I'. + RETURN. ENDCASE. RETURN. ENDIF. @@ -198,12 +200,35 @@ CLASS /mbtools/cl_command__show IMPLEMENTATION. ENDIF. SPLIT lv_param AT ';' INTO TABLE lt_param. - FIND REGEX '\\PROGRAM=(.+)\\CLASS' IN TABLE lt_param SUBMATCHES lv_object. IF sy-subrc <> 0. FIND REGEX 'RS38M-PROGRAMM=(.+)' IN TABLE lt_param SUBMATCHES lv_object ##SUBRC_OK. + CHECK sy-subrc <> 0. + " if skip initial screen is checked and it is assigned to t-code + FIND REGEX '\/\*(\w+)' IN TABLE lt_param SUBMATCHES lv_object. + IF sy-subrc = 0. + lv_object_is_tcode = abap_true. + ENDIF. + CHECK sy-subrc <> 0. + " if skip initial screen is not checked + FIND REGEX '\/N(\w+)' IN TABLE lt_param SUBMATCHES lv_object. + IF sy-subrc = 0. + lv_object_is_tcode = abap_true. + ENDIF. + ENDIF. + IF lv_object IS NOT INITIAL AND lv_object_is_tcode. + CALL FUNCTION 'SRT_GET_REPORT_OF_TCODE' + EXPORTING + tcode = lv_object + IMPORTING + report_structure = ls_report + EXCEPTIONS + no_report_transaction = 1 + OTHERS = 2. + rs_tadir_key-object = 'PROG'. + rs_tadir_key-obj_name = ls_report-report. + RETURN. ENDIF. - IF lv_object IS NOT INITIAL. rs_tadir_key-object = 'PROG'. rs_tadir_key-obj_name = lv_object. From 0360cf95103e61bd647ce82a81dea3525ae74b28 Mon Sep 17 00:00:00 2001 From: Ali Bayest <65496394+Alih-b@users.noreply.github.com> Date: Wed, 17 Apr 2024 10:55:23 +0330 Subject: [PATCH 3/5] #12 added support for more types of parameter t-codes --- src/#mbtools#cl_command__show.clas.abap | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/#mbtools#cl_command__show.clas.abap b/src/#mbtools#cl_command__show.clas.abap index 6ce9b86..13c7cc8 100644 --- a/src/#mbtools#cl_command__show.clas.abap +++ b/src/#mbtools#cl_command__show.clas.abap @@ -188,7 +188,7 @@ CLASS /mbtools/cl_command__show IMPLEMENTATION. OTHERS = 2. rs_tadir_key-obj_name = ls_report-report. WHEN OTHERS. - MESSAGE 'It is a generated report' type 'I'. + MESSAGE 'It is a generated report' TYPE 'I'. RETURN. ENDCASE. RETURN. @@ -216,7 +216,7 @@ CLASS /mbtools/cl_command__show IMPLEMENTATION. lv_object_is_tcode = abap_true. ENDIF. ENDIF. - IF lv_object IS NOT INITIAL AND lv_object_is_tcode. + IF lv_object IS NOT INITIAL AND lv_object_is_tcode = abap_true. CALL FUNCTION 'SRT_GET_REPORT_OF_TCODE' EXPORTING tcode = lv_object From 7c902340d46fcc18074b4f7c08fa1ff0f46d98c0 Mon Sep 17 00:00:00 2001 From: Marc Bernard Date: Wed, 17 Apr 2024 12:15:45 +0000 Subject: [PATCH 4/5] Refactor & unit tests --- src/#mbtools#cl_command__show.clas.abap | 136 +++++++++--------- ...ols#cl_command__show.clas.testclasses.abap | 120 ++++++++++++++++ src/#mbtools#cl_command__show.clas.xml | 1 + 3 files changed, 192 insertions(+), 65 deletions(-) create mode 100644 src/#mbtools#cl_command__show.clas.testclasses.abap diff --git a/src/#mbtools#cl_command__show.clas.abap b/src/#mbtools#cl_command__show.clas.abap index 13c7cc8..0c8736e 100644 --- a/src/#mbtools#cl_command__show.clas.abap +++ b/src/#mbtools#cl_command__show.clas.abap @@ -57,6 +57,12 @@ CLASS /mbtools/cl_command__show DEFINITION RETURNING VALUE(rs_tadir_key) TYPE /mbtools/if_definitions=>ty_tadir_key. + CLASS-METHODS get_report_from_tcode + IMPORTING + !iv_tcode TYPE csequence + RETURNING + VALUE(rs_report) TYPE srepovari. + ENDCLASS. @@ -146,91 +152,53 @@ CLASS /mbtools/cl_command__show IMPLEMENTATION. METHOD get_object_from_tcode. DATA: - lv_tcode TYPE tstc-tcode, - lv_param TYPE tstcp-param, - lt_param TYPE string_table, - ls_report TYPE srepovari, - ls_mtdkey TYPE seocpdkey, + lv_param TYPE tstcp-param, + lt_param TYPE string_table, + ls_report TYPE srepovari, + ls_mtdkey TYPE seocpdkey, lv_object_is_tcode TYPE abap_bool, - lv_object TYPE c LENGTH 120. + lv_object TYPE c LENGTH 120. - lv_tcode = iv_object_name. + rs_tadir_key-pgmid = 'R3TR'. + rs_tadir_key-object = 'PROG'. - rs_tadir_key-pgmid = 'R3TR'. + " Dialog transaction + SELECT SINGLE pgmna INTO lv_object FROM tstc WHERE tcode = iv_object_name. + IF lv_object IS NOT INITIAL. + rs_tadir_key-obj_name = lv_object. + RETURN. + ENDIF. - " Report transaction - CALL FUNCTION 'SRT_GET_REPORT_OF_TCODE' - EXPORTING - tcode = lv_tcode - IMPORTING - report_structure = ls_report - EXCEPTIONS - no_report_transaction = 1 - OTHERS = 2. - IF sy-subrc = 0 AND ls_report-report IS NOT INITIAL. - rs_tadir_key-object = 'PROG'. + " Report transactions + ls_report = get_report_from_tcode( iv_object_name ). + IF ls_report-report IS NOT INITIAL. CASE ls_report-reporttype. WHEN ''. rs_tadir_key-obj_name = ls_report-report. WHEN 'TR'. - " It is very unlikely to have a parameter t-code for - " another parameter t-code - " and SAP discourages it with warning - " so this is sufficient - lv_tcode = ls_report-report. - CALL FUNCTION 'SRT_GET_REPORT_OF_TCODE' - EXPORTING - tcode = lv_tcode - IMPORTING - report_structure = ls_report - EXCEPTIONS - no_report_transaction = 1 - OTHERS = 2. - rs_tadir_key-obj_name = ls_report-report. + " It is very unlikely to have a parameter t-code for another parameter t-code + " and SAP discourages it with warning so this is sufficient + rs_tadir_key-obj_name = get_report_from_tcode( ls_report-report )-report. WHEN OTHERS. MESSAGE 'It is a generated report' TYPE 'I'. - RETURN. ENDCASE. RETURN. ENDIF. + " Parameter Transaction - SELECT SINGLE param INTO lv_param FROM tstcp WHERE tcode = lv_tcode. + SELECT SINGLE param INTO lv_param FROM tstcp WHERE tcode = iv_object_name. IF sy-subrc <> 0. RETURN. ENDIF. SPLIT lv_param AT ';' INTO TABLE lt_param. + FIND REGEX '\\PROGRAM=(.+)\\CLASS' IN TABLE lt_param SUBMATCHES lv_object. IF sy-subrc <> 0. - FIND REGEX 'RS38M-PROGRAMM=(.+)' IN TABLE lt_param SUBMATCHES lv_object ##SUBRC_OK. - CHECK sy-subrc <> 0. - " if skip initial screen is checked and it is assigned to t-code - FIND REGEX '\/\*(\w+)' IN TABLE lt_param SUBMATCHES lv_object. - IF sy-subrc = 0. - lv_object_is_tcode = abap_true. - ENDIF. - CHECK sy-subrc <> 0. - " if skip initial screen is not checked - FIND REGEX '\/N(\w+)' IN TABLE lt_param SUBMATCHES lv_object. - IF sy-subrc = 0. - lv_object_is_tcode = abap_true. - ENDIF. + FIND REGEX 'RS38M-PROGRAMM=(.+)' IN TABLE lt_param SUBMATCHES lv_object. ENDIF. - IF lv_object IS NOT INITIAL AND lv_object_is_tcode = abap_true. - CALL FUNCTION 'SRT_GET_REPORT_OF_TCODE' - EXPORTING - tcode = lv_object - IMPORTING - report_structure = ls_report - EXCEPTIONS - no_report_transaction = 1 - OTHERS = 2. - rs_tadir_key-object = 'PROG'. - rs_tadir_key-obj_name = ls_report-report. - RETURN. - ENDIF. - IF lv_object IS NOT INITIAL. - rs_tadir_key-object = 'PROG'. + + IF sy-subrc = 0. rs_tadir_key-obj_name = lv_object. RETURN. ENDIF. @@ -247,9 +215,8 @@ CLASS /mbtools/cl_command__show IMPLEMENTATION. IF ls_mtdkey-cpdname IS NOT INITIAL. rs_tadir_key-object = 'PROG'. rs_tadir_key-obj_name = cl_oo_classname_service=>get_method_include( ls_mtdkey ). - ELSE. - RETURN. ENDIF. + RETURN. ENDIF. FIND REGEX 'TABLENAME=(.+)' IN TABLE lt_param SUBMATCHES lv_object. @@ -287,6 +254,45 @@ CLASS /mbtools/cl_command__show IMPLEMENTATION. RETURN. ENDIF. + " if skip initial screen is checked and it is assigned to t-code + FIND REGEX '\/\*([\w|\/]+)' IN TABLE lt_param SUBMATCHES lv_object. + IF sy-subrc = 0. + lv_object_is_tcode = abap_true. + ELSE. + " if skip initial screen is not checked + FIND REGEX '\/N([\w|\/]+)' IN TABLE lt_param SUBMATCHES lv_object. + IF sy-subrc = 0. + lv_object_is_tcode = abap_true. + ENDIF. + ENDIF. + + IF lv_object_is_tcode = abap_true. + rs_tadir_key-object = 'PROG'. + rs_tadir_key-obj_name = get_report_from_tcode( lv_object )-report. + RETURN. + ENDIF. + + ENDMETHOD. + + + METHOD get_report_from_tcode. + + DATA lv_tcode TYPE tstc-tcode. + + lv_tcode = iv_tcode. + + CALL FUNCTION 'SRT_GET_REPORT_OF_TCODE' + EXPORTING + tcode = lv_tcode + IMPORTING + report_structure = rs_report + EXCEPTIONS + no_report_transaction = 1 + OTHERS = 2. + IF sy-subrc <> 0. + CLEAR rs_report. + ENDIF. + ENDMETHOD. diff --git a/src/#mbtools#cl_command__show.clas.testclasses.abap b/src/#mbtools#cl_command__show.clas.testclasses.abap new file mode 100644 index 0000000..3aa53c8 --- /dev/null +++ b/src/#mbtools#cl_command__show.clas.testclasses.abap @@ -0,0 +1,120 @@ + +CLASS ltcl_command_show DEFINITION FOR TESTING RISK LEVEL HARMLESS + DURATION SHORT FINAL. + + PRIVATE SECTION. + METHODS: + test + IMPORTING + iv_tcode TYPE csequence + iv_type TYPE csequence + iv_name TYPE csequence, + dialog_transaction FOR TESTING, + report_transaction FOR TESTING, + oo_transaction FOR TESTING, + variant_transaction FOR TESTING, + parameter_transaction FOR TESTING. + +ENDCLASS. + +CLASS /mbtools/cl_command__show DEFINITION LOCAL FRIENDS ltcl_command_show. + +CLASS ltcl_command_show IMPLEMENTATION. + + METHOD test. + + DATA ls_tstc TYPE tstc. + DATA ls_act TYPE /mbtools/if_definitions=>ty_tadir_key. + + SELECT SINGLE * INTO ls_tstc FROM tstc WHERE tcode = iv_tcode. + CHECK sy-subrc = 0. + + ls_act = /mbtools/cl_command__show=>get_object_from_tcode( iv_tcode ). + + cl_abap_unit_assert=>assert_equals( + act = ls_act-object + exp = iv_type ). + cl_abap_unit_assert=>assert_equals( + act = ls_act-obj_name + exp = iv_name ). + + ENDMETHOD. + + METHOD dialog_transaction. + + test( + iv_tcode = 'SE16' + iv_type = 'PROG' + iv_name = 'SAPLSETB' ). + + ENDMETHOD. + + METHOD report_transaction. + + test( + iv_tcode = 'SE91' + iv_type = 'PROG' + iv_name = 'RSMESSAGES' ). + + ENDMETHOD. + + METHOD oo_transaction. + + " OO transactional model + test( + iv_tcode = 'SE20' + iv_type = 'PROG' + iv_name = 'CL_ENHANCEMENTS===============CM001' ). + + " Local OO transactional model + test( + iv_tcode = 'SE30' + iv_type = 'PROG' + iv_name = 'SATRA_START' ). + + ENDMETHOD. + + METHOD variant_transaction. + + test( + iv_tcode = 'SU0' + iv_type = 'PROG' + iv_name = 'SAPMSUU0O' ). + + ENDMETHOD. + + METHOD parameter_transaction. + + test( + iv_tcode = 'SCC4' + iv_type = 'VIEW' + iv_name = 'T000' ). + + test( + iv_tcode = 'SEGW' + iv_type = 'PROG' + iv_name = '/IWBEP/R_SBUI_SERVICE_BUILDER' ). + + test( + iv_tcode = 'SE80' + iv_type = 'PROG' + iv_name = 'SAPMSEU0' ). + + test( + iv_tcode = 'RBDAPP01' + iv_type = 'PROG' + iv_name = 'RBDAPP01' ). + + test( + iv_tcode = 'SE16T000' + iv_type = 'TABL' + iv_name = 'T000' ). + + test( + iv_tcode = 'STRORG' + iv_type = 'WDYA' + iv_name = 'CTS_ORGANIZER' ). + + ENDMETHOD. + +ENDCLASS. diff --git a/src/#mbtools#cl_command__show.clas.xml b/src/#mbtools#cl_command__show.clas.xml index 409f5b0..82f328f 100644 --- a/src/#mbtools#cl_command__show.clas.xml +++ b/src/#mbtools#cl_command__show.clas.xml @@ -12,6 +12,7 @@ X K /MBTOOLS/BC_CL + X From 65e96e620fd2085c38bc4d65eef1e433767f98eb Mon Sep 17 00:00:00 2001 From: Marc Bernard Date: Wed, 17 Apr 2024 12:18:57 +0000 Subject: [PATCH 5/5] replace select * --- src/#mbtools#cl_command__show.clas.testclasses.abap | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/#mbtools#cl_command__show.clas.testclasses.abap b/src/#mbtools#cl_command__show.clas.testclasses.abap index 3aa53c8..bb9de95 100644 --- a/src/#mbtools#cl_command__show.clas.testclasses.abap +++ b/src/#mbtools#cl_command__show.clas.testclasses.abap @@ -23,10 +23,10 @@ CLASS ltcl_command_show IMPLEMENTATION. METHOD test. - DATA ls_tstc TYPE tstc. + DATA lv_tcode TYPE tstc-tcode. DATA ls_act TYPE /mbtools/if_definitions=>ty_tadir_key. - SELECT SINGLE * INTO ls_tstc FROM tstc WHERE tcode = iv_tcode. + SELECT SINGLE tcode INTO lv_tcode FROM tstc WHERE tcode = iv_tcode. CHECK sy-subrc = 0. ls_act = /mbtools/cl_command__show=>get_object_from_tcode( iv_tcode ).