Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for more types of parameter t-codes #13

Merged
merged 5 commits into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
106 changes: 78 additions & 28 deletions src/#mbtools#cl_command__show.clas.abap
Original file line number Diff line number Diff line change
Expand Up @@ -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.


Expand Down Expand Up @@ -146,34 +152,41 @@ 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_object TYPE c LENGTH 120.

lv_tcode = iv_object_name.

rs_tadir_key-pgmid = 'R3TR'.
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.

rs_tadir_key-pgmid = 'R3TR'.
rs_tadir_key-object = 'PROG'.

" 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'.
rs_tadir_key-obj_name = ls_report-report.
" 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
rs_tadir_key-obj_name = get_report_from_tcode( ls_report-report )-report.
WHEN OTHERS.
MESSAGE 'It is a generated report' TYPE 'I'.
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.
Expand All @@ -182,11 +195,10 @@ CLASS /mbtools/cl_command__show IMPLEMENTATION.

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.
FIND REGEX 'RS38M-PROGRAMM=(.+)' IN TABLE lt_param SUBMATCHES lv_object.
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.
Expand All @@ -203,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.
Expand Down Expand Up @@ -243,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.


Expand Down
120 changes: 120 additions & 0 deletions src/#mbtools#cl_command__show.clas.testclasses.abap
Original file line number Diff line number Diff line change
@@ -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 lv_tcode TYPE tstc-tcode.
DATA ls_act TYPE /mbtools/if_definitions=>ty_tadir_key.

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 ).

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.
1 change: 1 addition & 0 deletions src/#mbtools#cl_command__show.clas.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<UNICODE>X</UNICODE>
<RSTAT>K</RSTAT>
<MSG_ID>/MBTOOLS/BC_CL</MSG_ID>
<WITH_UNIT_TESTS>X</WITH_UNIT_TESTS>
</VSEOCLASS>
<TPOOL>
<item>
Expand Down
Loading