Report to search ABAP code in Enhancement implementations
With SAP Standard report RS_ABAP_SOURCE_SCAN or the SAP Code Inspector (transaction SCI) it is not possible to do text based searches through Enhancement Implementations
Inspired by the archived discussion here, I put together below little ABAP code scanner for Enhancement implementations.
Features
- Full Text search in ABAP code inside implicit- and explicit Enhancement implementations/spots.
- Limit search range by Development Package
- Simple list output with matching enhancements & line of code where hit occurred
- No further fancy stuff.
Enjoy
*&---------------------------------------------------------------------*
*& Report Z_SCAN_ENHANCEMENTS
*&---------------------------------------------------------------------*
*& Search enhencement implementation code for given string.
*& Joris Bots - July 2018
*&---------------------------------------------------------------------*
REPORT z_scan_enhancements.
DATA lv_percentage TYPE i.
DATA lv_old_percentage TYPE i.
DATA lv_text TYPE c LENGTH 150.
DATA ls_enhincinx TYPE enhincinx.
DATA lt_enhincinx TYPE STANDARD TABLE OF enhincinx.
DATA lt_source TYPE abaptxt255_tab.
DATA lt_results TYPE match_result_tab.
PARAMETERS p_srch TYPE string.
PARAMETERS p_class TYPE devclass.
START-OF-SELECTION.
"Accept wildcards for dev class || set wildcard for all
IF p_class IS INITIAL.
p_class = '%'.
ELSE.
REPLACE ALL OCCURRENCES OF '*' IN p_class WITH '%'.
ENDIF.
"Get all enhancement spots that are in the selected dev class
SELECT e~* FROM
enhincinx AS e
INNER JOIN tadir AS t ON 'R3TR' = t~pgmid
AND 'ENHO' = t~object
AND e~enhname = t~obj_name
WHERE t~devclass LIKE @p_class
INTO TABLE @lt_enhincinx.
LOOP AT lt_enhincinx ASSIGNING FIELD-SYMBOL(<ls_enhincinx>).
"Talk to the user
lv_percentage = sy-tabix * 100 / lines( lt_enhincinx ).
lv_text = |Searching Enhancements ({ sy-tabix }/{ lines( lt_enhincinx ) })...|.
IF lv_old_percentage <> lv_percentage.
CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
EXPORTING
percentage = lv_percentage
text = lv_text.
lv_old_percentage = lv_percentage.
ENDIF.
READ REPORT <ls_enhincinx>-enhinclude INTO lt_source.
CLEAR lt_results.
FIND ALL OCCURRENCES OF p_srch IN TABLE lt_source
IN CHARACTER MODE
IGNORING CASE
RESULTS lt_results.
IF lt_results IS NOT INITIAL.
SKIP.
WRITE: / '++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++'.
WRITE: / |{ <ls_enhincinx>-programname } / { <ls_enhincinx>-full_name } / { <ls_enhincinx>-enhname }:|.
ENDIF.
LOOP AT lt_results ASSIGNING FIELD-SYMBOL(<ls_result>).
WRITE :/ lt_source[ <ls_result>-line ]-line.
ENDLOOP.
ENDLOOP.
I have been looking for something like this. Excellent work. I have a suggestion though. Why not host this on github so that people can develop on this. Like you said - no fancy stuff right now, but others might want to develop other fancy stuff on top of this. Just my two cents. Cheers! 🙂
Hi Karthikeyan,
Thanks for the reply. I coded this little piece because I needed the functionality. I figured it might be useful for others as well, so I posted it here.
I feel Github is for software projects and I don't think this is, or should be one. But I encourage others to take this code and bring it to Github and turn it into something great.
Best regards,
Joris
Hello Joris,
you could create an abapGit project and link it to save us the effort to enter the code manually. Further, specifying an open source license tells others are welcome to re-publish the code if they make change, like mine below.
JNN
Where were you when I needed this few years ago? 🙂
Second the suggestion to put this on Github. Then others could also make changes and maybe even add "fancy stuff". 🙂 That's a win-win.
Thanks for sharing!
Very nice, thanks!
A related, useful function would be to search customer modified code. One could use the Information from table SMODILOG as basis, and then parse the Code where lines like
occur.
And it would be great to have These functions built into the Standard SAP Code search report (which, to my Knowledge, is Report RS_ABAP_SOURCE_SCAN).
Edit, September 19: I just wrote a blog about extending RS_ABAP_SOURCE_SCAN to search enhancements and modifications: https://blogs.sap.com/2018/09/19/code-search-in-modifications-and-enhancements/
Nice, very nice!
Hi,
Try EWK1 tcode.
Regards