惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Martin Fowler
Martin Fowler
爱范儿
爱范儿
博客园_首页
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
大猫的无限游戏
大猫的无限游戏
月光博客
月光博客
IT之家
IT之家
WordPress大学
WordPress大学
N
Netflix TechBlog - Medium
Microsoft Azure Blog
Microsoft Azure Blog
The GitHub Blog
The GitHub Blog
C
Check Point Blog
Apple Machine Learning Research
Apple Machine Learning Research
博客园 - Franky
G
Google Developers Blog
V
V2EX
雷峰网
雷峰网
美团技术团队
博客园 - 【当耐特】
人人都是产品经理
人人都是产品经理
有赞技术团队
有赞技术团队
MongoDB | Blog
MongoDB | Blog
V
Visual Studio Blog
J
Java Code Geeks

博客园 - Raymond Zhang

案例分享:电信行业零售业务CRM架构 客户关系管理及客户服务简介(译) How-to: disable the web-security-check in Chrome for Mac 基于HANA Cloud的SAP Mobility Platform正式发布 Some notes about CRM Roles Concept in Web UI Fixing the SAPOSS RFC connection via Secure Storage Migration How-to: Move the items in local to specific packages Some basic skills (2) - Configure the printer for your SAP systems A trouble shooting case - Background job ZABC failed Gateway Notes (1) SAP Netweaver Gateway Add-on for Backend System Installation Some basic skills (1) - Change the background image after logon Why is “GUID” used in SAP CRM? SPM (Service Parts Management) Inter-Company STO - CRM Billing issue Enhancement on SAP CRM Web UI page toolbar How to estimate the active condition records in a CRM system (2) How to estimate the active condition records in a CRM system (1) How-to: Set up the delta upload for Vendor Master Data from CRM to ERP Introduction of new feature ‘Tag Cloud’ with SAP CRM 7.0 Ehp 1
Automate debugging using ABAP debugger scripts
Raymond Zhang · 2013-04-02 · via 博客园 - Raymond Zhang

I would like to share a very detailed and useful document guiding how to use Script in Debugging from SAPTechnical.

Introduction:-

There must be many situations in which you have to debug very complex SAP standard or custom code. It might be possible that you have to check all the RFC calls, database updates, authority checks etc.

But as you might very well know, that complex applications can have very large number of these statements. Checking the result of each statement in debugger can be very cumbersome. Using debugger scripts, you can automate the above process and pin point the particular statement in the code.

Example: Here, I have created a demo program which contains some ‘Select’ statements. We wish to check the statement, which is not returning SY-SUBRC = 0. Note that this is a test program and you might not appreciate the use of scripts here. But applying the same technique in large programs can increase your productivity significantly.

There are some select statements in the above program. We wish to know which statement is giving SY-SUBRC = 4.

Steps:-

1. Enter in debug mode in the code in which you want to check. Open the script tab.

2. Now, change the trigger of the script. Tick the checkbox ‘Breakpoint reached’.

3. Note that, the breakpoint for the script trigger is not the same one as we create in ABAP. For triggering in script, you would have to create your breakpoint through script.

Click on the ‘Change’ button in front of ‘Breakpoint Reached’ checkbox.

Create a breakpoint for ABAP statement ‘Select’.

4. Now that the trigger is created. We have to write the code to analyze the statement at which the script is triggered. All the code can be easily generated using ‘Script wizard’ and has to be written in method ‘Script’. Following are the steps which we need to perform using script.

- The script will trigger at the ‘Select’ statement. Execute this statement

- Get the value of the program variable ‘SY-SUBRC’.

- Analyze the sy-subrc value. If sy-subrc NE 0, we will trigger the breakpoint.

a. So, we will use script wizard to step over (execute) the current statement (‘Select’). Remember to pass the parameter for ‘F5’ from the flower box that we get after selecting the Debug step. (Refer to attached code)

b. Get the value of the system variable ‘SY-SUBRC’ using script wizard.

c. Check the value of the variable obtained and if it is not 0, then trigger the breakpoint. The attached code is the final code, which would be generated using script wizard and slight modifications.

  METHOD script.
*** insert your script code here
*1. Step over the current statement (Select)
*************************************************
* debugger commands (p_command):
* Step into(F5)   -> CL_TPDA_SCRIPT_DEBUGGER_CTRL=>DEBUG_STEP_INTO
* Execute(F6)     -> CL_TPDA_SCRIPT_DEBUGGER_CTRL=>DEBUG_STEP_OVER
* Return(F7)      -> CL_TPDA_SCRIPT_DEBUGGER_CTRL=>DEBUG_STEP_OUT
* Continue(F8)    -> CL_TPDA_SCRIPT_DEBUGGER_CTRL=>DEBUG_CONTINUE
*************************************************
****************************************************************
*Interface (CLASS = CL_TPDA_SCRIPT_DEBUGGER_CTRL / METHOD = DEBUG_STEP )
*Importing
*        REFERENCE( P_COMMAND ) TYPE I
****************************************************************
    TRY.
        CALL METHOD debugger_controller->debug_step
          EXPORTING
            p_command = cl_tpda_script_debugger_ctrl=>debug_step_into.
      CATCH cx_tpda_scr_rtctrl_status .
      CATCH cx_tpda_scr_rtctrl .
    ENDTRY.
*2. Get the value of the system variable 'sy-subrc'
****************************************************************
*Interface (CLASS = CL_TPDA_SCRIPT_DATA_DESCR / METHOD = GET_SIMPLE_VALUE )
*Importing
*        REFERENCE( P_VAR_NAME ) TYPE TPDA_VAR_NAME
*Returning
*        VALUE( P_VAR_VALUE ) TYPE TPDA_VAR_VALUE
****************************************************************
    DATA lv_subrc TYPE sy-subrc.
    TRY.
        CALL METHOD cl_tpda_script_data_descr=>get_simple_value
          EXPORTING
            p_var_name  = 'SY-SUBRC'
          RECEIVING
            p_var_value = lv_subrc.
      CATCH cx_tpda_varname .
      CATCH cx_tpda_script_no_simple_type .
    ENDTRY.
*3.Check the value of sy-subrc. Trigger point, if condition reached
    IF lv_subrc NE 0.
      me->break( ).
    ENDIF.
  ENDMETHOD.                    "script
  METHOD end.
*** insert your code which shall be executed at the end of the scripting (before trace is saved)
*** here
  ENDMETHOD.                    "end  

5. Check the syntax of the code and start the script (using the button on the left of Pattern’.

6. It will stop at the point where the select statement doesn’t return sy-subrc as 0.

So, the debugger has stopped at the position where SY-SUBRC is not 0.

7. Now, we have the option to either continue the script (to find more such select statements), or exit the script and manually debug from that point onwards. We will exit the script and go to debugger to check the SY-SUBRC value.

So, the SY-SUBRC is 4.

Note: If after starting the script, it goes to the output screen directly, you can press back and exit the script.

Summary:

The above technique can be used for other statements as well like RFC calls, Authority checks, call method etc.

Also, you can explore the script wizard and there are a lot of things which you can do. There are a lot of standard scripts available. You can either use them directly or modify them according to your requirement.

We have written the script on the fly. We can also save our script for reusability

We can also see the trace of our debugger script, which can be very useful if we are going for layer aware debugging.

Raymond Zhang
If you want to discuss with me about any idea, please contact me at raymond.zhang@sap.com