0039 - Searching Programs For Strings

Moderators: Snowy, thx4allthefish, Rich, ilya

Post Reply
Rich
Posts: 7116
Joined: Thu Oct 31, 2002 4:47 pm
Location: Liverpool
Contact:

0039 - Searching Programs For Strings

Post by Rich » Sat Mar 28, 2009 8:45 am

Searching Programs For Strings.

You can use standard program RPR_ABAP_SOURCE_SCAN to search ABAP program code/screen logic for specific texts (strings.)
This program offers many more options than programs RSRSCAN1 or RKCTSEAR. The benefits of using this program are as follows:
  • Several texts can be entered for which the system searches. The search text should be entered without formatting characters(*,+). Only the texts are applied in the search, i.e. selection option conditions such as greater than, equal to, etc., are ignored
  • You can restrict the search to either the program code or the flow logic of the selected screens or both the program code and the flow logic of the screens.
  • You can set the option to ignore the comments for search.
  • Found location +/- x lines: Here we can specify how many program lines before and after the found location of the search string should be included in the output.
  • We can also specify the option to search in all the includes used in the specified programs.
Shortly after this, Baerbel sent me this:
Baerbel wrote:When I first saw the program mentioned on SAPFans a while ago I tried it and saw that it works fine with displaying the search-results. But, if you want to drill down into the code by clicking on one of the lines displayed, you not always end up where you want to be. After some debugging I discovered, that the problem occurs, if you don't want to search in commented out lines. During loop precessing, the program physically deletes those lines from the internal table containing the source-code of the program being searched. This leads to an incorrect index which is nonetheless used for positioning to drill down into the program.

As I wanted to use the program, I created a local copy and commented out the following lines (208):

Code: Select all

  if rb_dyn is initial. 
    loop at itab. 

      read table irdir_tmp with key obj_name = itab-repname. 
      if sy-subrc = 0. 
        continue. 
      endif. 

      read report itab-repname into rtab. 
      check sy-subrc = 0. 
*      if not comment is initial. 
*        delete rtab 
*          where text(1) = '*'. 
*      endif. 
Baerbel wrote:A bit further down, I've added my own comment-processing without touching the index:

Code: Select all

        loop at rtab from sy-tabix. 
          tabix      = sy-tabix. 
          rtab_lcase = rtab. 
          translate rtab to upper case. 

          if not comment is initial. 
            if rtab-text(1) = '*'. 
              continue. 
            endif. 
          endif. 
Baerbel wrote:As I then already had a modifiable Y-version, I added some more changes to make the report a bit better readable (an empty line after a "hit", a page-number in the header, more space in the header so that the date isn't cut short, a checkbox on the selection-screen and the necessary code to include temp-programs in the search).
Regards

Rich

Image
Abap KC:http://www.richard-harper.me.uk/Kb
SFMDR:http://www.se37.com

Post Reply