Skip to content

Commit

Permalink
Show corresponding object for transactions (#11)
Browse files Browse the repository at this point in the history
* Show corresponding code for transactions

`?show <transaction>` displays the definition of the transaction code. Now, if you append `#` to the transaction, the corresponding base object of the transaction will be shown.

Examples:

- `?show nwbc#`: display method `cl_nwbc->se93_launch`
- `?show se91#`: display program `rsmessage`

* Split into table

* Parameter parsing
  • Loading branch information
mbtools authored Apr 15, 2024
1 parent ba9de68 commit af424c1
Show file tree
Hide file tree
Showing 3 changed files with 202 additions and 7 deletions.
28 changes: 27 additions & 1 deletion src/#mbtools#cl_command.clas.abap
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ CLASS /mbtools/cl_command DEFINITION
RETURNING
VALUE(rr_range) TYPE /mbtools/if_definitions=>ty_name_range.

METHODS name_adjust
IMPORTING
!iv_obj_name TYPE csequence
RETURNING
VALUE(rv_obj_name) TYPE string.

METHODS object_split
IMPORTING
!iv_object TYPE string
Expand Down Expand Up @@ -212,6 +218,22 @@ CLASS /mbtools/cl_command IMPLEMENTATION.
ENDMETHOD.


METHOD name_adjust.

DATA lv_len TYPE i.

lv_len = strlen( iv_obj_name ) - 1.

" Remove trailing #
IF lv_len > 0 AND iv_obj_name+lv_len(1) = '#'.
rv_obj_name = iv_obj_name(lv_len).
ELSE.
rv_obj_name = iv_obj_name.
ENDIF.

ENDMETHOD.


METHOD name_split.

DATA:
Expand All @@ -225,6 +247,8 @@ CLASS /mbtools/cl_command IMPLEMENTATION.
IF iv_obj_name CS c_split-values.
SPLIT iv_obj_name AT c_split-values INTO TABLE lt_obj_name.
LOOP AT lt_obj_name INTO lv_obj_name.
lv_obj_name = name_adjust( lv_obj_name ).

APPEND INITIAL LINE TO rr_range ASSIGNING <lr_range>.

range_derive(
Expand All @@ -240,11 +264,13 @@ CLASS /mbtools/cl_command IMPLEMENTATION.
<lr_range>-high = /mbtools/cl_sap=>object_name_check( <lr_range>-high ).
ENDLOOP.
ELSE.
lv_obj_name = name_adjust( iv_obj_name ).

APPEND INITIAL LINE TO rr_range ASSIGNING <lr_range>.

range_derive(
EXPORTING
iv_input = iv_obj_name
iv_input = lv_obj_name
IMPORTING
ev_sign = <lr_range>-sign
ev_option = <lr_range>-option
Expand Down
162 changes: 161 additions & 1 deletion src/#mbtools#cl_command__show.clas.abap
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,24 @@ CLASS /mbtools/cl_command__show DEFINITION
RETURNING
VALUE(rv_exit) TYPE abap_bool.

CLASS-METHODS show_code
IMPORTING
!is_tadir_key TYPE /mbtools/if_definitions=>ty_tadir_key
RETURNING
VALUE(rv_exit) TYPE abap_bool.

CLASS-METHODS is_code_command
IMPORTING
!iv_object_name TYPE csequence
RETURNING
VALUE(rv_result) TYPE abap_bool.

CLASS-METHODS get_object_from_tcode
IMPORTING
!iv_object_name TYPE csequence
RETURNING
VALUE(rs_tadir_key) TYPE /mbtools/if_definitions=>ty_tadir_key.

ENDCLASS.


Expand Down Expand Up @@ -90,7 +108,11 @@ CLASS /mbtools/cl_command__show IMPLEMENTATION.
ENDTRY.

" Show object definition
cv_exit = show_tool( ls_tadir_key ).
IF is_code_command( lv_object_name ) = abap_true.
cv_exit = show_code( ls_tadir_key ).
ELSE.
cv_exit = show_tool( ls_tadir_key ).
ENDIF.

IF lv_tadir_count = 1.
EXIT.
Expand Down Expand Up @@ -121,6 +143,144 @@ CLASS /mbtools/cl_command__show IMPLEMENTATION.
ENDMETHOD.


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

" 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.
RETURN.
ENDIF.

" Parameter Transaction
SELECT SINGLE param INTO lv_param FROM tstcp WHERE tcode = lv_tcode.
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.
ENDIF.

IF lv_object IS NOT INITIAL.
rs_tadir_key-object = 'PROG'.
rs_tadir_key-obj_name = lv_object.
RETURN.
ENDIF.

FIND REGEX '\\CLASS=(.+)\\METHOD=(.+)' IN TABLE lt_param SUBMATCHES ls_mtdkey-clsname ls_mtdkey-cpdname.
IF sy-subrc <> 0.
FIND REGEX 'CLASS=(.+)' IN TABLE lt_param SUBMATCHES ls_mtdkey-clsname ##SUBRC_OK.
FIND REGEX 'METHOD=(.+)' IN TABLE lt_param SUBMATCHES ls_mtdkey-cpdname ##SUBRC_OK.
ENDIF.

IF ls_mtdkey-clsname IS NOT INITIAL.
rs_tadir_key-object = 'CLAS'.
rs_tadir_key-obj_name = ls_mtdkey-clsname.
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.
ENDIF.

FIND REGEX 'TABLENAME=(.+)' IN TABLE lt_param SUBMATCHES lv_object.
IF sy-subrc = 0.
rs_tadir_key-object = 'TABL'.
rs_tadir_key-obj_name = lv_object.
RETURN.
ENDIF.

FIND REGEX 'VIEWNAME=(.+)' IN TABLE lt_param SUBMATCHES lv_object.
IF sy-subrc = 0.
rs_tadir_key-object = 'VIEW'.
rs_tadir_key-obj_name = lv_object.
RETURN.
ENDIF.

FIND REGEX 'VCLNAME=(.+)' IN TABLE lt_param SUBMATCHES lv_object.
IF sy-subrc = 0.
rs_tadir_key-object = 'VIEW'.
rs_tadir_key-obj_name = lv_object.
RETURN.
ENDIF.

FIND REGEX 'APPLICATION=(.+)' IN TABLE lt_param SUBMATCHES lv_object.
IF sy-subrc = 0.
rs_tadir_key-object = 'WDYA'.
rs_tadir_key-obj_name = lv_object.
RETURN.
ENDIF.

FIND REGEX 'TNRO-OBJECT=(.+)' IN TABLE lt_param SUBMATCHES lv_object.
IF sy-subrc = 0.
rs_tadir_key-object = 'NROB'.
rs_tadir_key-obj_name = lv_object.
RETURN.
ENDIF.

ENDMETHOD.


METHOD is_code_command.

DATA lv_len TYPE i.

lv_len = strlen( iv_object_name ) - 1.

rv_result = boolc( lv_len > 0 AND iv_object_name+lv_len(1) = '#' ).

ENDMETHOD.


METHOD show_code.

DATA ls_tadir_key LIKE is_tadir_key.

" Show ABAP code corresponding to object
ls_tadir_key = is_tadir_key.

IF ls_tadir_key-pgmid = 'R3TR' AND ls_tadir_key-object = 'TRAN'.
" transactions -> program / class / view
ls_tadir_key = get_object_from_tcode( ls_tadir_key-obj_name ).
ENDIF.

IF ls_tadir_key = is_tadir_key.
MESSAGE 'No corresponding ABAP code found' TYPE 'S'.
ELSE.
rv_exit = /mbtools/cl_sap=>show_object(
iv_pgmid = ls_tadir_key-pgmid
iv_object = ls_tadir_key-object
iv_obj_name = ls_tadir_key-obj_name ).
ENDIF.

ENDMETHOD.


METHOD show_message.

DATA:
Expand Down
19 changes: 14 additions & 5 deletions src/#mbtools#if_command_field.intf.abap
Original file line number Diff line number Diff line change
@@ -1,24 +1,28 @@
INTERFACE /mbtools/if_command_field
PUBLIC .
INTERFACE /mbtools/if_command_field PUBLIC .

************************************************************************
* MBT Command Field
*
* Copyright 2021 Marc Bernard <https://marcbernardtools.com/>
* SPDX-License-Identifier: GPL-3.0-only
************************************************************************

" TODO: Replace with /mbtools/cl_sap constants

CONSTANTS:
BEGIN OF c_pgmid,
r3tr TYPE pgmid VALUE 'R3TR',
limu TYPE pgmid VALUE 'LIMU',
basis TYPE pgmid VALUE 'ZZZZ',
END OF c_pgmid .
basis TYPE pgmid VALUE 'ZZ01',
END OF c_pgmid.

CONSTANTS:
BEGIN OF c_objects_db,
tabl TYPE adir_key-object VALUE 'TABL',
c1 TYPE c VALUE ',',
view TYPE adir_key-object VALUE 'VIEW',
END OF c_objects_db.

CONSTANTS:
BEGIN OF c_objects_bw,
all TYPE adir_key-object VALUE 'BW',
Expand Down Expand Up @@ -53,6 +57,7 @@ INTERFACE /mbtools/if_command_field
c14 TYPE c VALUE ',',
trpr TYPE adir_key-object VALUE 'TRPR',
END OF c_objects_bw.

CONSTANTS:
BEGIN OF c_objects_abap,
prog TYPE adir_key-object VALUE 'PROG',
Expand All @@ -71,10 +76,12 @@ INTERFACE /mbtools/if_command_field
c7 TYPE c VALUE ',',
type TYPE adir_key-object VALUE 'TYPE',
END OF c_objects_abap.

CONSTANTS:
BEGIN OF c_objects_limu,
mess TYPE adir_key-object VALUE 'MESS',
END OF c_objects_limu.

CONSTANTS:
BEGIN OF c_objects_exec,
prog TYPE adir_key-object VALUE 'PROG',
Expand All @@ -83,6 +90,7 @@ INTERFACE /mbtools/if_command_field
c2 TYPE c VALUE ',',
func TYPE adir_key-object VALUE 'FUNC',
END OF c_objects_exec.

CONSTANTS:
BEGIN OF c_table_class,
transp TYPE dd02l-tabclass VALUE 'TRANSP',
Expand All @@ -97,8 +105,8 @@ INTERFACE /mbtools/if_command_field
c5 TYPE c VALUE ',',
append TYPE dd02l-tabclass VALUE 'APPEND',
END OF c_table_class.

CONSTANTS:
" Matches /mbtools/cl_sap=>class_constructor
BEGIN OF c_objects_basis,
activity TYPE adir_key-object VALUE 'ZACT',
c1 TYPE c VALUE ',',
Expand All @@ -122,4 +130,5 @@ INTERFACE /mbtools/if_command_field
c10 TYPE c VALUE ',',
user TYPE adir_key-object VALUE 'ZUSR',
END OF c_objects_basis.

ENDINTERFACE.

0 comments on commit af424c1

Please sign in to comment.