Find modifications in executed code
Identifying Modified Objects during Report Execution Using a Debugger Script
In SAP, tracking modifications made during the execution of a report can sometimes be tricky. For example, the SMODILOG table contains entries of all modifications, but it doesn’t provide detailed information on which specific objects (e.g., includes, methods) were executed during the report’s runtime. To solve this problem, we devised a strategy using a Debugger Script to compare executed includes or methods against the entries in SMODILOG and detect modified objects. Although we could not pinpoint the exact lines of code that were modified, identifying which objects were modified was sufficient for our task.
Steps Involved
- Understand SMODILOG:
- The SMODILOG table tracks modifications for non-Z/Y objects that are edited in the system.
- Entries in this table indicate the modified objects but do not specify the lines that were modified.
- Create a Debugger Script:
- The main goal is to create a debugger script that monitors each line executed in the report and checks if the include or method being executed corresponds to any entry in SMODILOG.
- If the executed include or method matches an object from SMODILOG, we flag it as a modified object.
- Debugger Script Code:
Here is an example of the Debugger Script that compares executed includes/methods with SMODILOG entries.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
CLASS lcl_debugger_script DEFINITION INHERITING FROM cl_tpda_script_class_super.
PUBLIC SECTION.
METHODS:
init REDEFINITION,
script REDEFINITION,
end REDEFINITION,
prologue REDEFINITION.
PRIVATE SECTION.
TYPES: BEGIN OF t_include,
name TYPE smodilog-obj_name,
END OF t_include.
DATA: lt_smodilog TYPE HASHED TABLE OF smodilog
WITH UNIQUE KEY obj_name sub_name int_name.
DATA: lt_includes TYPE TABLE OF t_include.
ENDCLASS.
CLASS lcl_debugger_script IMPLEMENTATION.
METHOD prologue.
" Initialize ABAP source (source handler for ABAP)
super->prologue( ).
ENDMETHOD.
METHOD init.
" Retrieve all modifications from SMODILOG table
SELECT *
FROM smodilog
INTO TABLE lt_smodilog
WHERE operation EQ 'MOD'.
ENDMETHOD.
METHOD script.
DATA: ls_custom TYPE tpda_trace_custom.
TRY.
" Get the current include being executed
DATA(lf_include) = abap_source->include( ).
" Check if the include is already processed
IF NOT line_exists( lt_includes[ name = lf_include ] ).
" Search if the include is modified (check against SMODILOG entries)
READ TABLE lt_smodilog WITH KEY obj_name = lf_include
sub_name = lf_include
TRANSPORTING NO FIELDS.
IF sy-subrc EQ 0.
" If the include was modified, add it to the list
APPEND VALUE #( name = lf_include )
TO lt_includes.
ENDIF.
ENDIF.
CATCH cx_root.
RETURN.
ENDTRY.
ENDMETHOD.
METHOD end.
DATA: ls_custom TYPE tpda_trace_custom.
" Sort and remove duplicate entries
SORT lt_includes.
DELETE ADJACENT DUPLICATES FROM lt_includes.
" Add the modified includes to the trace log
LOOP AT lt_includes ASSIGNING FIELD-SYMBOL(<s_include>).
ls_custom-value = <s_include>-name.
trace->add_custom_info( p_trace_entry = ls_custom ).
ENDLOOP.
ENDMETHOD.
ENDCLASS.
Explanation of the Code
- Initialization (
init
Method):- The
init
method selects all entries from the SMODILOG table where the operation is'MOD'
, which identifies modified objects. These entries are stored in the internal tablelt_smodilog
.
- The
- Script Execution (
script
Method):- The
script
method runs for each line executed in the program. It retrieves the current include being executed usingabap_source->include()
. - It checks whether the include is already processed by searching for it in
lt_includes
. If not, it checks whether the include exists in SMODILOG. If found, the include is marked as modified and added tolt_includes
.
- The
- End Method (
end
Method):- At the end of the script, the
lt_includes
table is sorted and duplicates are removed. Then, each modified include is added to the trace log usingtrace->add_custom_info
.
- At the end of the script, the
Running the Debugger Script
- Once you execute the report, the debugger script will track every line being executed and compare the current include with the modified entries in SMODILOG.
- After execution, the list of modified includes or methods will be displayed, giving you insight into which objects were modified during the report execution.
Final words
Using a debugger script allows us to efficiently track modified objects during the execution of a report, comparing each executed include or method with entries in SMODILOG. Although we cannot compare at the line level, identifying modified objects was sufficient to achieve the desired results. This approach is valuable for debugging and auditing report execution when dealing with changes to standard SAP objects.