Some small ABAP tools I write to improve daily work efficiency or just for fun
- 1. Tcode Usage Statistics Tool
- 2. ABAP Class Version Browse Tool
- 3. Development History Trace Tool
- 4. A compare tool: Download and analyze the runtime performance result from SAT
- 5. Execute some transaction code without logging on to backend system
- 6. XML difference compare tool
- 7. Mischief: send a message to another online user
- 8. BSP page browse history tool
Tcode Usage Statistics Tool
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.


ABAP Class Version Browse Tool

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.




Development History Trace Tool
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.

A compare tool: Download and analyze the runtime performance result from SAT
Execute some transaction code without logging on to backend system

Sub CommandButton1_Click()
Set R3 = CreateObject("SAP.Functions")
Set myConnction = R3.Connection
myConnction.ApplicationServer = "replace with your own host name here!!!"
myConnction.SystemNumber = 54
myConnction.Client = "001"
myConnction.user = "replace with your own user here!!!"
myConnction.Password = "replace with your own password here!!!"
If myConnction.Logon(0, True) <> True Then
MsgBox "Logon failed"
Exit Sub
End If
Dim callFunctionModule As Object
Set callFunctionModule = R3.Add("TH_USER_LIST")
callFunctionModule.Call
If callFunctionModule.Exception <> "" Then
MsgBox callFunctionModule.Exception
End If
If callFunctionModule.Call = True Then
Dim result As Object
Set result = callFunctionModule.tables("USRLIST")
Dim aSheet As Worksheet
Dim sheetCol As New Collection
sheetCol.Add ActiveWorkbook.Sheets(1)
For Each aSheet In sheetCol
Dim i As Integer
i = 1
For Each user In result.Rows
Client = user(2)
UserName = user(3)
Terminal = user(5)
IP = user(16)
aSheet.Cells(i, 1) = Client
aSheet.Cells(i, 2) = UserName
aSheet.Cells(i, 3) = Terminal
aSheet.Cells(i, 4) = IP
i = i + 1
Next
Next
Else
MsgBox " Call Failed! error: "
End If
'log off
myConnction.logoff
End Sub
With this script I am calling function module TH_USER_LIST from excel, parse the result and display them in excel.
Now I click the button, I can observe in ABAP system that the function module TH_USER_LIST is called:
And result is displayed in excel:
XML difference compare tool
No need to download additional software to compare the different XML, as there is a standard class cl_proxy_ui_utils which can do this task for you.
See the following sample code:
DATA: lv_original TYPE xstring,
lv_changed TYPE xstring.
lv_original = zcl_jerry_tool=>get_file_binary_by_path( 'C:\temp\1.xml' ).
lv_changed = zcl_jerry_tool=>get_file_binary_by_path( 'C:\temp\2.xml' ).
CALL METHOD cl_proxy_ui_utils=>show_xml_diff
EXPORTING
doc1 = lv_original
doc2 = lv_changed.
Execute the report and there will be a popup where the difference is displayed. The implementation of ZCL_JERRY_TOOL=>GET_FILE_BINARY_BY_PATH could be found here.
Mischief: send a message to another online user



BSP page browse history tool
The title might be a little bit misleading. To be more exact, this tool lists all automatically generated ABAP classes for BSP pages accessed by a given user.
Simply execute the report with a user name:
And detail browser list is displayed:
You can find more background information regarding BSP and JSP, and also the source code of this tool from my blog JSP attribute tag used in Hybris UI implementation and counterpart in ABAP BSP.
Jerry - Cool, thank you for sharing. Â Both are nice tools!
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
I got it, Class Version Browse Tool is very useful one. Thanks again.
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)
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
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
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
Hi Jerry,
may you want to share your made extensions regarding the new syntax within ABAP? Could save me some work:-)
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
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
I wouldn't consider myself lazy if I improve my work efficiency 😉 Good job btw!
Cool.
nice
nice
Hi, I tried to copy the code snippet given for Tcode history of a user..its not working for me..it doesn't show up any tcodes I used.