Skip to Content

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.
To report this post you need to login first.

5 Comments

You must be Logged on to comment or reply to a post.

  1. Karthikeyan Ravikumar

    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! 🙂

    (1) 
    1. J. Bots Post author

      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

      (0) 
      1. Jacques Nomssi

        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.

        *&---------------------------------------------------------------------*
        *& Report Z_SCAN_ENHANCEMENTS
        *&---------------------------------------------------------------------*
        *& Search enhancement implementation code for given string.
        *& Joris Bots - July 2018 - Refactoring by JNN
        *& https://blogs.sap.com/2018/07/22/report-to-search-abap-code-in-enhancement-implementations/
        *&---------------------------------------------------------------------*
        REPORT z_scan_enhancements.
        TYPES tt_enhincinx TYPE STANDARD TABLE OF enhincinx.
        
        PARAMETERS p_srch TYPE string.
        PARAMETERS p_class TYPE devclass.
        
        START-OF-SELECTION.
          PERFORM scan USING p_srch p_class.
        
        FORM scan USING pv_search TYPE string
                        pv_devclass TYPE devclass.
          DATA lt_enhincinx TYPE tt_enhincinx.
        * Accept wildcards for dev class || set wildcard for all
          DATA lv_class TYPE devclass VALUE '%'.
          IF pv_devclass IS NOT INITIAL.
            lv_class = pv_devclass.
            REPLACE ALL OCCURRENCES OF '*' IN lv_class WITH '%'.
          ENDIF.
        
          PERFORM query_spots USING lv_class CHANGING lt_enhincinx.
          PERFORM match_enhancements USING lt_enhincinx.
        ENDFORM.
        
        FORM query_spots USING pv_class TYPE devclass
                         CHANGING ct_enhincinx TYPE tt_enhincinx.
        * Get all enhancement spots that are in the selected dev class
          SELECT e~* FROM enhincinx AS e "Enhancement: Table across program enhancements
              INNER JOIN tadir AS t ON 'R3TR' = t~pgmid
                                   AND 'ENHO' = t~object
                                   AND e~enhname = t~obj_name
            WHERE t~devclass LIKE @pv_class
            INTO TABLE @ct_enhincinx.
        ENDFORM.
        
        FORM match_enhancements USING pt_enhincinx TYPE tt_enhincinx.
          DATA lt_source TYPE abaptxt255_tab.
        
          LOOP AT pt_enhincinx ASSIGNING FIELD-SYMBOL(<ls_enhincinx>).
            AT FIRST.
              DATA(lv_max) = lines( pt_enhincinx ).
            ENDAT.
        
            PERFORM progress USING sy-tabix lv_max.
        
            READ REPORT <ls_enhincinx>-enhinclude INTO lt_source.
        
            FIND ALL OCCURRENCES OF p_srch IN TABLE lt_source
              IN CHARACTER MODE IGNORING CASE
              RESULTS DATA(lt_results).
            CHECK sy-subrc EQ 0.
        
            PERFORM output_list USING <ls_enhincinx> lt_source lt_results.
          ENDLOOP.
        ENDFORM.
        
        FORM output_list USING ps_enhincinx TYPE enhincinx
                                   pt_source TYPE abaptxt255_tab
                                   pt_results TYPE match_result_tab.
          LOOP AT pt_results ASSIGNING FIELD-SYMBOL(<ls_result>).
            AT FIRST.
              SKIP.
              WRITE / '++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++'.
              WRITE / |{ ps_enhincinx-programname } / { ps_enhincinx-full_name } / { ps_enhincinx-enhname }:|.
            ENDAT.
        
            WRITE / pt_source[ <ls_result>-line ]-line.
          ENDLOOP.
        ENDFORM.
        
        FORM progress USING iv_tabix TYPE sytabix
                            iv_max TYPE sytabix.
          STATICS old_percentage TYPE i.
          DATA lv_text TYPE c LENGTH 150.
        
        * Talk to the user
          DATA(lv_percentage) = iv_tabix * 100 / iv_max.
          lv_text = |Searching Enhancements ({ iv_tabix }/{ iv_max })...|.
          CHECK old_percentage <> lv_percentage.
          CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
            EXPORTING
              percentage = lv_percentage
              text       = lv_text.
          old_percentage = lv_percentage.
        ENDFORM.

        JNN

        (1) 
  2. Jelena Perfiljeva

    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!

    (0) 
  3. Edo von Glan

     

    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

    *{   INSERT

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

    (0) 

Leave a Reply