I write some small ABAP tools for my daily work. Some of them might not be so useful at first glance – I just write them for fun. Some of them could be used to improve work efficiency, to just reduce several mouse clicks – I am too lazy 🙂

Tcode Usage Statistics Tool

This 56 lines of report can print the tcode usage for a given user per month.
REPORT ZTCODE.

PARAMETERS: month TYPE dats DEFAULT sy-datum OBLIGATORY,
           user type usr02-bname OBLIGATORY DEFAULT sy-uname.

TYPES: BEGIN OF zusertcode,
         operation type char30,
         type type char10,
         count  TYPE swncshcnt,
       END OF zusertcode.

TYPES: tt_zusertcode TYPE STANDARD TABLE OF zusertcode WITH KEY operation type.

DATA: lt_usertcode  TYPE swnc_t_aggusertcode,
      ls_result    TYPE zusertcode,
      lt_result     TYPE tt_zusertcode.

CONSTANTS: cv_tcode TYPE char30 VALUE 'Tcode',
           cv_report TYPE char30 VALUE 'Report',
           cv_count TYPE char5 value 'Count'.

START-OF-SELECTION.

  CALL FUNCTION 'SWNC_COLLECTOR_GET_AGGREGATES'
    EXPORTING
      component     = 'TOTAL'
      periodtype    = 'M'
      periodstrt    = month
    TABLES
      usertcode     = lt_usertcode
    EXCEPTIONS
      no_data_found = 1
      OTHERS        = 2.

  DELETE lt_usertcode WHERE tasktype <> '01'.

  LOOP AT lt_usertcode ASSIGNING FIELD-SYMBOL(<user>) WHERE account = user.
     CLEAR: ls_result.
     ls_result-operation = <user>-entry_id.
     ls_result-type = <user>-entry_id+72.
     ls_result-count = <user>-count.
     COLLECT ls_result INTO lt_result.
  ENDLOOP.

  SORT lt_result BY count DESCENDING.

  WRITE:  10 cv_tcode, 20 cv_report, 60 cv_count COLOR COL_NEGATIVE.
  LOOP AT lt_result ASSIGNING FIELD-SYMBOL(<result>).
      IF <result>-type = 'T'.
        WRITE: / <result>-operation COLOR COL_TOTAL UNDER cv_tcode,
                 <result>-count COLOR COL_POSITIVE UNDER cv_count.
      ELSE.
        WRITE: / <result>-operation COLOR COL_GROUP UNDER cv_report,
                 <result>-count COLOR COL_POSITIVE UNDER cv_count.
      ENDIF.
  ENDLOOP.
For example if you would like to check the tcode usage for user WANGJER during March 2017, you have to just choose any date in March and execute:
It shows I have used SAT for 692 times. Looks like I have some performance trouble on March?
The similar function could be found in tcode ST03N.

ABAP Class Version Browse Tool

ABAP workbench has built-in version management tool.
The version comparison could only be performed against two version at a time.
Sometimes I have the requirement to do some pure text analysis on the source code version, for example I need to figure out on which version a variable is introduced. So I write this small tool, which can downloads all the versions of source code into a text file, then I can simply use text analysis tool to fulfill my query.
Execute this 38 lines of tool and it will print out the source code of all versions of specified method.
REPORT tool_abap_class_version_tool.

PARAMETERS: cname TYPE seocompo-clsname OBLIGATORY DEFAULT 'CL_CRM_OPPORTUNITY_MPC_EXT',
            mname TYPE seocompo-cmpname OBLIGATORY DEFAULT 'DEFINE_OPPORTUNITY'.

DATA: lv_name      TYPE vrsd-objname,
      lt_version   TYPE STANDARD TABLE OF vrsd,
      lt_table     TYPE STANDARD TABLE OF abaptxt255,
      lt_trdir     TYPE STANDARD TABLE OF trdir,
      lt_vsmodisrc TYPE STANDARD TABLE OF smodisrc,
      lt_vsmodilog TYPE STANDARD TABLE OF smodilog.

lv_name = cname && '%' && mname.

SELECT objname versno datum zeit FROM vrsd INTO CORRESPONDING FIELDS OF TABLE lt_version
   WHERE objname LIKE lv_name ORDER BY versno DESCENDING. "#EC CI_NOFIRST

LOOP AT lt_version ASSIGNING FIELD-SYMBOL(<version>).
  CALL FUNCTION 'SVRS_GET_REPS_FROM_OBJECT'
    EXPORTING
      object_name = <version>-objname
      object_type = 'METH'
      versno      = <version>-versno
    TABLES
      repos_tab   = lt_table
      trdir_tab   = lt_trdir
      vsmodisrc   = lt_vsmodisrc
      vsmodilog   = lt_vsmodilog.

  ASSERT sy-subrc = 0.

  WRITE: / 'version number: ' COLOR COL_GROUP, <version>-versno COLOR COL_NEGATIVE,
  'Date: ' COLOR COL_KEY, <version>-datum COLOR COL_HEADING, ' time: ' COLOR COL_POSITIVE, <version>-zeit COLOR COL_NORMAL.

  LOOP AT lt_table ASSIGNING FIELD-SYMBOL(<line>).
    WRITE: / <line>-line.
  ENDLOOP.
ENDLOOP.
The left task is to download it locally via Workbench:
Now I can review all the 77 versions of this method in a single text file.
Sublime Text is my favorite local text editor, as you can see from above screenshot there is also ABAP plugin for it to display ABAP source code with correct syntax highlight.
In Sublime Text it is possible to open the same file in separate two views so it is very convenience for me now to compare any two versions within the same editor window.

Development History Trace Tool

For example if I would like to recall what I have changed between 2017-03-01 and 2017-03-25, I can simply execute this 67 lines of reports:
PARAMETERS: name TYPE usr02-bname OBLIGATORY,
            fro  TYPE sy-datum OBLIGATORY DEFAULT sy-datum,
            to_  TYPE sy-datum OBLIGATORY DEFAULT sy-datum.

CONSTANTS: c_name TYPE trdir-name VALUE 'Name',
           c_date TYPE trdir-udat VALUE 'Date'.

AT SELECTION-SCREEN.
  IF fro > to_.
    WRITE: / 'Invalid date period.' COLOR COL_NEGATIVE.
    RETURN.
  ENDIF.

START-OF-SELECTION.
  DATA: lt_record TYPE STANDARD TABLE OF trdir.

  SELECT name udat INTO CORRESPONDING FIELDS OF TABLE lt_record FROM trdir
     WHERE unam = name AND udat BETWEEN fro AND to_.

  IF sy-subrc <> 0.
    WRITE: / 'No record found at given date period.' COLOR COL_NEGATIVE.
    RETURN.
  ENDIF.

  SORT lt_record BY udat DESCENDING.

  WRITE:  10 c_name, 80 c_date.

  LOOP AT lt_record INTO DATA(ls_data).
    WRITE: / ls_data-name UNDER c_name COLOR COL_POSITIVE, ls_data-udat UNDER c_date COLOR COL_TOTAL.
    HIDE ls_data-name.
  ENDLOOP.

AT LINE-SELECTION.
  DATA: bdcdata_tab  TYPE TABLE OF bdcdata,
        opt          TYPE ctu_params,
        bdcdata_line TYPE bdcdata.

  bdcdata_line-program = 'SAPLWBABAP'.
  bdcdata_line-dynpro = '0100'.
  bdcdata_line-dynbegin = 'X'.
  APPEND bdcdata_line TO bdcdata_tab.

  CLEAR: bdcdata_line.

  bdcdata_line-fnam = 'BDC_CURSOR'.
  bdcdata_line-fval = 'RS38M-PROGRAMM'.
  APPEND bdcdata_line TO bdcdata_tab.


  CLEAR: bdcdata_line.
  bdcdata_line-fnam = 'BDC_OKCODE'.
  bdcdata_line-fval = '=SHOP'.
  APPEND bdcdata_line TO bdcdata_tab.

  CLEAR: bdcdata_line.
  bdcdata_line-fnam = 'RS38M-PROGRAMM'.
  bdcdata_line-fval = ls_data-name.
  APPEND bdcdata_line TO bdcdata_tab.

  opt-dismode = 'E'.
  opt-defsize = 'X'.

  CALL TRANSACTION 'SE38' USING bdcdata_tab  OPTIONS FROM opt.
  CLEAR: bdcdata_tab.

Double click on each entry, and ABAP editor will be opened to allow me to review the source code of chosen entry.
This tool is especially useful for me as when I grow old, sometimes I didn’t remember what I have changed several days ago, and if I only make changes on Z objects then there will be no log in transport requests. Use this tool and I can immediately realize what I have changed for a given time interval.

A compare tool: Download and analyze the runtime performance result from SAT

To report this post you need to login first.

12 Comments

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

    1. Jerry Wang Post author

      Hello Tuncay,

      Thanks a lot for reading, in fact there are three tools not two – I forget to upload the source code of ABAP Class Version Browse Tool. Now the missing source code is uploaded.

      Best regards,

      Jerry

      (0) 
  1. Sandra Rossi

    Jerry, thanks for your nice blog. Did I miss something or the code is missing for your tool “ABAP class Version Browse Tool […] small tool, which can downloads all the versions of source code into a text file”. I’m also interested to know which text analysis tool you use for multiple comparisons at a time? (I use comparison in notepad++ but it’s only 2 texts at a time)

    (1) 
    1. Jerry Wang Post author

      Hello Sandra,

      I am sorry I forget to attach source code, and now it’s done. Please kindly check the corresponding part of the blog. Thanks a lot for reading!

      Best regards,

      Jerry

      (2) 
  2. Peter Inotai

    Hi Jerry,

    Thanks for sharing these tools and also the hint for Sublime Text editor. Until now I used Notepad++ (with ABAP included, of course 🙂 ), but now I tried Sublime and it’s also nice. Thanks!

    Best regards,

    Peter

     

    (0) 
    1. Jerry Wang Post author

      Hi Peter,

      The reason I prefer Sublime is it is allowed to define custom keyword for syntax highlight: since there are several new keyword in Netweaver 740 and higher version, in order to enable them with correct syntax highlight, it is very convenient to just add them to file in Data\Packages\ABAP\ABAP.tmLanguage:

      After it is added:

      Best regards,

      Jerry

      (1) 
        1. Jerry Wang Post author

          Hello  Florian,

          tips about ABAP plugin in Sublime Text has been well documented in its github repository 🙂

          In case you would like to refer to my customized file, you can find it here.

          Best regards,

          Jerry

          (1) 
      1. Peter Inotai

        Hi Jerry,

        Thanks for the info! Actually adding new keyword is also quit easy in Notepad++, but there comparison is only possible to two files as far as I know.

        Best regards,

        Peter

         

        (0) 

Leave a Reply