`
JerryWang_SAP
  • 浏览: 1032343 次
  • 性别: Icon_minigender_1
  • 来自: 成都
文章分类
社区版块
存档分类
最新评论

ABAP Debugging Script(调试器脚本)使用的一些实际例子

阅读更多

例子1:Use ABAP debugger script to view BOL entity content in an efficient way

In CRM, if we could like to review a BOL entity content in debugger, for example consider the following sample code which fetches line item product of a given one order document:

DATA:
      lo_collection      TYPE REF TO if_bol_entity_col,
      lv_view_name       TYPE crmt_view_name,
      lv_query_name      TYPE crmt_ext_obj_name,
      ls_parameter       TYPE genilt_query_parameters,
      lt_query_parameter TYPE genilt_selection_parameter_tab,
      ls_query_parameter LIKE LINE OF lt_query_parameter.

    ls_query_parameter-attr_name = 'OBJECT_ID'.
    ls_query_parameter-low = iv_oppt_id.
    ls_query_parameter-option = 'EQ'.
    ls_query_parameter-sign = 'I'.
    APPEND ls_query_parameter TO lt_query_parameter.

    ls_query_parameter-attr_name = 'PROCESS_TYPE'.
    ls_query_parameter-low = iv_process_type.
    ls_query_parameter-option = 'EQ'.
    ls_query_parameter-sign = 'I'.
    APPEND ls_query_parameter TO lt_query_parameter.

    so_core = cl_crm_bol_core=>get_instance( ).
    so_core->load_component_set( 'BT' ).
    lv_query_name = 'BTQ1Order'.

    DATA(lo_result) = so_core->dquery(
        iv_query_name               = lv_query_name
        is_query_parameters         = ls_parameter
        it_selection_parameters             = lt_query_parameter
        iv_view_name                = lv_view_name ).

    CHECK lo_result->size( ) = 1.
    DATA(lo_order_result) = lo_result->get_first( ).

    DATA(lo_bt_order) = lo_order_result->get_related_entity( 'BTADVS1Ord' ).
    CHECK lo_bt_order IS NOT INITIAL.

    DATA(lo_header) = lo_bt_order->get_related_entity( 'BTOrderHeader' ).

    CHECK lo_header IS NOT INITIAL.

    DATA(lo_items) = lo_header->get_related_entities( iv_relation_name = 'BTHeaderItemsExt' ).
    CHECK lo_items->size( ) = 1.

    DATA(lo_item) = lo_items->get_first( ).

    DATA(lo_admini) = lo_item->get_related_entity( 'BTItemsFirstLevel' ).
    CHECK lo_admini IS NOT INITIAL.

    DATA(lo_product) = lo_admini->get_related_entity( 'BTItemProductExt' ).

If you would like to review the content of lo_product, you have to:

(1) double click container_proxy:

 

 

(2) double click DATA_REF:

 

 

(3) double click:

 

 

(4) double click ATTRIBUTE_REF:

 

 

(5) double click:

 

 

So totally you need to perform FIVE times double click in order to review content:

 

 

Using ABAP debugger script

(1) Click Script tab:

 

 

(2) Create a new script:

 

 

Choose a name for your script:

 

 

(3) Use the following source code to overwrite the default source code:

*---------------------------------------------------------------------*
*       CLASS lcl_debugger_script DEFINITION
*---------------------------------------------------------------------*
*
*---------------------------------------------------------------------*
CLASS lcl_debugger_script DEFINITION INHERITING FROM  cl_tpda_script_class_super  .

  PUBLIC SECTION.
    METHODS: prologue  REDEFINITION,
      init    REDEFINITION,
      script  REDEFINITION,
      end     REDEFINITION.
    INTERFACES: if_tpda_script_w_input,
      if_tpda_script_w_output.

  PRIVATE SECTION.
    DATA: entity_name TYPE string.
    DATA: value TYPE string.
    DATA: output TYPE tpda_transfer_it_unsorted.
    DATA: bol_object_name TYPE crmt_ext_obj_name.
    METHODS get_attribute
      IMPORTING io_oref_descr     TYPE REF TO cl_tpda_script_orefdescr
                iv_attribute_name TYPE string
      RETURNING VALUE(ro_descr)   TYPE REF TO cl_tpda_script_data_descr.

ENDCLASS.                    "lcl_debugger_script DEFINITION
*---------------------------------------------------------------------*
*       CLASS lcl_debugger_script IMPLEMENTATION
*---------------------------------------------------------------------*
*
*---------------------------------------------------------------------*
CLASS lcl_debugger_script IMPLEMENTATION.

  METHOD prologue.
*** generate abap_source (source handler for ABAP)
    super->prologue( ).
  ENDMETHOD.                    "prolog

  METHOD if_tpda_script_w_input~get_parameters.

    DATA lt_input      TYPE tpda_transfer_it.
    DATA ls_input      TYPE tpda_transfer_struc.

    ls_input-id   = 'ENTITY'.
    APPEND ls_input TO lt_input.
    p_parameters_it = lt_input.

  ENDMETHOD.                    "if_tpda_script_w_input~get_parameters

  METHOD if_tpda_script_w_input~set_parameter_values.

*   Tabelle mit Inputparameter und Wert
    DATA lt_input     TYPE tpda_transfer_it.
    DATA ls_input     TYPE tpda_transfer_struc.

    lt_input = p_parameter_values_it.
    LOOP AT lt_input INTO ls_input.
      IF ls_input-id = 'ENTITY'.
        entity_name = ls_input-value.
      ENDIF.
    ENDLOOP.

  ENDMETHOD.                    "if_tpda_script_w_input~set_parameter_values

  METHOD init.
*** insert your initialization code here
  ENDMETHOD.                    "init

  METHOD script.

    DATA lr_data_descr      TYPE REF TO cl_tpda_script_data_descr.
    DATA lr_struct_descr    TYPE REF TO cl_tpda_script_structdescr.
    DATA lr_cx              TYPE REF TO cx_root.
    DATA ls_quick           TYPE tpda_scr_quick_info.
    DATA lv_name            TYPE string.
    DATA lt_struct          TYPE tpda_scr_struct_comp_it.
    DATA ls_struct          TYPE tpda_scr_struct_comp.
    DATA ls_output          TYPE tpda_transfer_struc.
    DATA lr_symbsimple      TYPE REF TO tpda_sys_symbsimple.
    DATA ls_varinfo         TYPE tpda_quick_vars.

    FIELD-SYMBOLS: <lv_value> TYPE any.

    TRY.
        CLEAR output.

*        BREAK-POINT.

        ls_varinfo = cl_tpda_script_data_descr=>get_variable_info( 'LO_PRODUCT' ).

*       get object type name
        IF ls_varinfo-varvalue = 'OBJECT'.
*         class instance passed directly
          lv_name = entity_name && '-CONTAINER_PROXY->DATA_REF->OBJECT_NAME'.
        ELSE.
*         variable of class instance passed
          lv_name = ls_varinfo-varvalue && '-CONTAINER_PROXY->DATA_REF->OBJECT_NAME'.
        ENDIF.

        ls_quick = cl_tpda_script_data_descr=>get_quick_info( lv_name ).
        ASSIGN ls_quick-quickdata TO <lv_value>.
        lr_symbsimple ?= <lv_value>.
        bol_object_name = lr_symbsimple->valstring.

*       get content
        IF ls_varinfo-varvalue = 'OBJECT'.
          lv_name = entity_name && '-CONTAINER_PROXY->DATA_REF->ATTRIBUTE_REF->*'.
        ELSE.
          lv_name = ls_varinfo-varvalue && '-CONTAINER_PROXY->DATA_REF->ATTRIBUTE_REF->*'.
        ENDIF.

        lr_data_descr = cl_tpda_script_data_descr=>factory( lv_name ).
        lr_struct_descr ?= lr_data_descr.

        lr_struct_descr->components(
          IMPORTING
*            p_components_it      =
            p_components_full_it =  lt_struct
        ).

        LOOP AT lt_struct INTO ls_struct.
          ls_output-id = ls_struct-compname.
          TRY.
              ASSIGN ls_struct-symbquick-quickdata TO <lv_value>.
              lr_symbsimple ?= <lv_value>.
              ls_output-value = lr_symbsimple->valstring.
            CATCH cx_root INTO lr_cx.
              ls_output-value = lr_cx->get_text( ).
          ENDTRY.
          APPEND ls_output TO output.
        ENDLOOP.

        DATA lt_col_alv                   TYPE tpda_script_service_source_tab.
        DATA ls_col_alv                   LIKE LINE OF lt_col_alv.
        ls_col_alv-fieldname = ls_col_alv-content = 'ID'.
        APPEND ls_col_alv TO lt_col_alv.
        ls_col_alv-fieldname = ls_col_alv-content = 'VALUE'.
        APPEND ls_col_alv TO lt_col_alv.

        CALL METHOD cl_tpda_script_data_display=>data_display
          EXPORTING
            p_list_header = 'Query Selection Parameters'
            p_column_it   = lt_col_alv
            p_popup       = 'X'
          CHANGING
            p_data_it     = output.

*        BREAK-POINT.
      CATCH cx_root INTO lr_cx.
        BREAK-POINT.                                       "#EC NOBREAK
        value = lr_cx->get_text( ).
    ENDTRY.
  ENDMETHOD.                    "script

  METHOD end.
*** insert your code which shall be executed at the end of the scripting (before trace is saved)
*** here

  ENDMETHOD.                    "end

  METHOD if_tpda_script_w_output~get_parameter_values.

    DATA lt_param TYPE tpda_transfer_it_unsorted.
    DATA ls_param TYPE tpda_transfer_struc.

    ls_param-id = 'VARIABLE'.
    ls_param-value = entity_name.
    APPEND ls_param TO lt_param.
    ls_param-id = 'OBJECT_NAME'.
    ls_param-value = bol_object_name.
    APPEND ls_param TO lt_param.

    APPEND INITIAL LINE TO lt_param.

    APPEND LINES OF output TO lt_param.

    p_parameter_values_it = lt_param.

  ENDMETHOD.                    "if_tpda_script_w_output~get_parameter_values

  METHOD get_attribute.

    DATA lr_oref_descr     TYPE REF TO cl_tpda_script_orefdescr.
    DATA lr_object_descr   TYPE REF TO cl_tpda_script_objectdescr.
    DATA ls_varinfo        TYPE tpda_quick_vars.
    DATA lv_longname       TYPE string.

    DATA lt_attributes TYPE tpda_script_object_attribut_it.

    lr_oref_descr   = io_oref_descr.
    lr_object_descr = lr_oref_descr->get_object_handle( ).

    lt_attributes = lr_object_descr->attributes( ).

    ro_descr = lr_object_descr->get_attribut_handle( lv_longname  ).

  ENDMETHOD.                    "get_oref_attribute

ENDCLASS.                    "lcl_debugger_script IMPLEMENTATION

Once done, save the script and choose “Execute Directly”.

 

 

(4) Before you start Script by clicking button “Start Script”, make sure you use the correct variable name used in your ABAP code. In my example, it is “LO_PRODUCT”.

 

 

Once done, click button “Start Script”: the BOL entity content is now automatically displayed, without five times double click any more.

 

 

例子2:Use ABAP debugger script to view dynamic query service selection parameter in an efficient way

In WebUI we can maintain search parameter for dynamic search:

 

 

The value maintained in WebUI could be found from dynamic query service instance in backend via debugging. Double click variable qs:

 

 

We need the following FIVE steps to see the selection parameter value.

(1) double click SELECTION_PARAM_COL:

 

 

(2) Double click ENTITY_LIST:

 

 

(3) These four entities represent the four selection parameters we see in WebUI. Double click one of them:

 

 

(4) Double click PARAMETER_DATA:

 

 

(5) double click:

 

 

Finally we see the value:

 

 

Use ABAP debugger script to directly review variable content without so many double clicks

(1) Click Script tab, create a new Script:

 

 

(2) Choose a name for your script:

 

 

Paste the following source code to overwrite automatically generated source code:

*---------------------------------------------------------------------*
*       CLASS lcl_debugger_script DEFINITION
*---------------------------------------------------------------------*
*
*---------------------------------------------------------------------*
CLASS lcl_debugger_script DEFINITION INHERITING FROM  cl_tpda_script_class_super  .

  PUBLIC SECTION.

    METHODS: prologue REDEFINITION,
             init     REDEFINITION,
             script   REDEFINITION,
             end      REDEFINITION.

    INTERFACES: if_tpda_script_w_input.


  PRIVATE SECTION.

    DATA      queryservicename TYPE string.
    CONSTANTS querydefaultname TYPE string VALUE 'QUERY_SERVICE'.

ENDCLASS.                    "lcl_debugger_script DEFINITION
*---------------------------------------------------------------------*
*       CLASS lcl_debugger_script IMPLEMENTATION
*---------------------------------------------------------------------*
*
*---------------------------------------------------------------------*
CLASS lcl_debugger_script IMPLEMENTATION.
  METHOD prologue.
*** generate abap_source (source handler for ABAP)
    super->prologue( ).
  ENDMETHOD.                    "prolog

  METHOD init.
    queryservicename = querydefaultname.
  ENDMETHOD.                    "init

  METHOD script.

    TYPES:
        BEGIN OF ty_selparam,
          attrname TYPE string,
          sign     TYPE string,
          option   TYPE string,
          low      TYPE string,
          high     TYPE string,
        END OF ty_selparam.

    DATA lt_col_alv                   TYPE tpda_script_service_source_tab.
    DATA ls_col_alv                   like LINE OF lt_col_alv.
    DATA ls_selparam                  TYPE ty_selparam.
    DATA lr_query_service             TYPE tpda_quick_vars.
    DATA lv_query_service_object_name TYPE tpda_var_name.
    DATA lv_selparamcol_object_name   TYPE tpda_var_name.
    DATA lv_bo_object_name            TYPE tpda_var_name.
    DATA lv_number_of_selparam        TYPE i.
    DATA lt_attr                      TYPE tpda_script_object_attribut_it.
    DATA ls_attr                      TYPE tpda_script_object_attributes.
    DATA lt_selparam                  TYPE STANDARD TABLE OF ty_selparam.
    DATA lr_attr                      TYPE REF TO cl_tpda_script_data_descr.
    DATA lr_entity_list               TYPE REF TO cl_tpda_script_tabledescr.
    DATA lr_obj_descr                 TYPE REF TO cl_tpda_script_objectdescr.

    REFRESH lt_selparam.

    TRY.
        lv_query_service_object_name = cl_tpda_script_data_descr=>get_variable_info( queryservicename )-varvalue.
        lv_selparamcol_object_name = cl_tpda_script_data_descr=>get_variable_info( lv_query_service_object_name && '-SELECTION_PARAM_COL' )-varvalue.
        lr_entity_list ?= cl_tpda_script_data_descr=>factory( lv_selparamcol_object_name && '-ENTITY_LIST' ).
        lv_number_of_selparam = lr_entity_list->linecnt( ).
        DO lv_number_of_selparam TIMES.
          lv_bo_object_name = cl_tpda_script_data_descr=>get_variable_info( lv_selparamcol_object_name && '-ENTITY_LIST[' && sy-index && ']-BO')-varvalue.
          ls_selparam-attrname = cl_tpda_script_data_descr=>get_simple_value( lv_bo_object_name && '-PARAMETER_DATA->ATTR_NAME' ).
          ls_selparam-option = cl_tpda_script_data_descr=>get_simple_value( lv_bo_object_name && '-PARAMETER_DATA->SIGN' ).
          ls_selparam-sign = cl_tpda_script_data_descr=>get_simple_value( lv_bo_object_name && '-PARAMETER_DATA->OPTION' ).
          ls_selparam-low = cl_tpda_script_data_descr=>get_simple_value( lv_bo_object_name && '-PARAMETER_DATA->LOW' ).
          ls_selparam-high = cl_tpda_script_data_descr=>get_simple_value( lv_bo_object_name && '-PARAMETER_DATA->HIGH' ).
          APPEND ls_selparam TO lt_selparam.
        ENDDO.
        REFRESH lt_col_alv.
        ls_col_alv-fieldname = ls_col_alv-content = 'ATTRNAME'.
        APPEND ls_col_alv TO lt_col_alv.
        ls_col_alv-fieldname = ls_col_alv-content = 'SIGN'.
        APPEND ls_col_alv TO lt_col_alv.
        ls_col_alv-fieldname = ls_col_alv-content = 'OPTION'.
        APPEND ls_col_alv TO lt_col_alv.
        ls_col_alv-fieldname = ls_col_alv-content = 'LOW'.
        APPEND ls_col_alv TO lt_col_alv.
        ls_col_alv-fieldname = ls_col_alv-content = 'HIGH'.
        APPEND ls_col_alv TO lt_col_alv.
        CALL METHOD cl_tpda_script_data_display=>data_display
          EXPORTING
            p_list_header = 'Query Selection Parameters'
            p_column_it   = lt_col_alv
            p_popup       = 'X'
          CHANGING
            p_data_it     = lt_selparam.

      CATCH cx_tpda_varname
            cx_tpda_data_descr_invalidated
            cx_sy_move_cast_error
            cx_tpda_table_wrong_key
            cx_tpda_script_no_simple_type
            cx_tpda_table_wrong_table_type.
        me->raise_error( ).
    ENDTRY.
  ENDMETHOD.                    "script

  METHOD end.
*** insert your code which shall be executed at the end of the scripting (before trace is saved)
*** here

  ENDMETHOD.                    "end

  METHOD if_tpda_script_w_input~get_parameters.

    DATA l_input   TYPE tpda_transfer_struc.

    IF p_parameters_it IS INITIAL.
      l_input-id      = 'Query Service Variable Name'.
      l_input-value   = querydefaultname.
      APPEND l_input TO p_parameters_it.
    ENDIF.

  ENDMETHOD.                    "if_tpda_script_w_input~get_parameters

  METHOD if_tpda_script_w_input~set_parameter_values.

    DATA l_input   TYPE tpda_transfer_struc.

    READ TABLE p_parameter_values_it INTO l_input INDEX 1.
    queryservicename = l_input-value.

  ENDMETHOD.                    "if_tpda_script_w_input~set_parameter_values

ENDCLASS.                    "lcl_debugger_script IMPLEMENTATION

Specify the name of your query service variable in line 21. In my example, it is QS. Start script by clicking button “Start Script”:

 

 

Now you see all four selection parameter value displayed in ALV.

 

 

要获取更多Jerry的原创文章,请关注公众号"汪子熙":

0
1
分享到:
评论

相关推荐

    SAP ABAP调试器的秘密:ABAP高级调试技术

    本文主要介绍了ABAP调试器的一些高级特性,包括深入调用堆栈、系统调试、更新调试以及增强调试效率的技巧。 1. **深入调用堆栈**:在常规的应用程序调试之外,开发者有时需要对调用堆栈的深层进行调试,尤其是当...

    ABAP SCRIPT

    - **A Sample SAP Scripts Reports.txt**:可能提供了一些示例报告的源代码,展示如何利用ABAP Script创建自定义报表,例如动态数据显示或用户交互处理。 - **demo in sap.txt**:可能是一个实际的Script演示,...

    SAP ABAP ScriptForm 中文版本

    ### SAP ABAP ScriptForm 中文版本 #### SAPscript的组成及功能详解 ##### 1.1 SAPscript的组成 SAPscript 是一种用于创建和管理SAP系统中的表单的技术,它由以下五个主要组成部分构成: 1. **编辑器**:负责...

    SAP SCRIPTFORM 学习例子

    SAP Scriptform是SAP系统中用于创建自定义打印输出的一种技术,它是SAP ABAP编程的一部分,专门处理复杂的报表和文档格式化。这个学习例子是针对初学者设计的,旨在帮助他们掌握SAP Scriptform的基本概念和操作,...

    abap script form 视频教材

    如果出现问题,可以通过调试器找出问题所在。 在视频教程中,你将逐步学习如何创建一个简单的ABAP Script Form,从创建基本结构到添加内容,再到实现条件判断和数据交互。同时,还会了解如何在实际项目中应用这些...

    ABAP 高级调试功能

    SAT采用了与新ABAP调试器相同的多工具管理器,支持用户根据需要自定义界面。用户可以在不同的视图之间切换查看跟踪数据,并且支持导航不同工具之间的数据展示。跟踪数据通过ALV网格或列树的形式展示。 #### 四、...

    ABAP-Object-Visualizer:使用调试器脚本可视化复杂的对象层次结构

    在新的调试器中,转到“脚本”选项卡 从数据库加载脚本ZRSTPDA_OBJECT_VISUALIZER 选择选项“直接执行” 点击“开始脚本” 输入对象变量名称 将剪贴板粘贴到 ,然后单击“生成图形!”。 Graphviz也可以在本地...

    ABAP动态内表使用的例子

    ### ABAP动态内表使用的例子 #### 一、引言 在ABAP编程语言中,动态内表(Dynamic Internal Tables)是一种非常灵活的数据结构,它允许程序员在运行时定义和操作内表。与静态内表相比,动态内表提供了更多的灵活性...

    ABAP基础资料+SAP Script编程指南

    ABAP(Advanced Business Application Programming)是SAP系统中的一种编程语言,主要用于开发企业级的应用程序。它是SAP R/3系统的核心组成部分,广泛应用于业务流程的定制化开发、报表生成、用户界面设计等方面。 ...

    ABAp高级调试功能

    为了有效地诊断并解决这些问题,SAP提供了强大的ABAP高级调试工具,其中包括新的ABAP运行时分析器(SAT)和新ABAP调试器等。这些工具能够帮助开发者在开发阶段就发现并修复潜在的问题,从而减少后期的维护成本。 ##...

    如何在后台模式下调试程序ABAP程序的运行

    此外,我们还可以使用其他的调试工具,例如ABAP调试器、系统日志等,以便更好地调试程序。这些工具可以帮助我们检测和解决程序中的错误,提高程序的稳定性和可靠性。 后台调试是ABAP程序调试的一个非常重要的方式。...

    New ABAP Debugger

    在深入了解新ABAP调试器之前,我们先来回顾一下旧版本调试器的一些限制,这有助于我们理解为什么需要推出一个全新的调试工具。 **传统调试器的问题:** 1. **调试范围受限:**由于传统的ABAP调试器与被调试的应用...

    ABAP 屏幕设计中添加文本编辑器

    ABAP 屏幕设计中添加文本编辑器是指在 SAP 业务系统中,使用文本编辑器处理内表,并在屏幕上显示编辑器,退出时将内容输出。本文将详细介绍如何在屏幕上显示编辑器,退出时将内容输出。 知识点1:建立屏幕 在建立...

    The New ABAP Debugger

    传统的ABAP调试器虽然功能强大,但在实际应用中存在一定的局限性。随着技术的发展和业务需求的变化,原有的调试工具已不能满足当前的需求。因此,SAP推出了新一代的ABAP调试器。 #### 经典调试器现状 经典ABAP调试...

    SAP ABAP SQL查询分析器(ABAP动态SQL执行)ZSQLEXPLORER

    这个是国外人使用ABAP写的一个类似一SQL Server的查询分析器,它能够直接运行ABAP的OPEN SQL,由于SE11或者是SE16都只能对一表进行查询,但很多的时候我们需要对多个表进行联合查询,这时就可以发挥很大作用了,希望...

    SAP ABAP Web dynpro 跟踪调试

    SAP ABAP Web dynpro 跟踪调试工具的讲解。

    SAPscript Forms 教程

    4. **程序接口**:通过将SAPscript组件嵌入到ABAP程序中,程序员可以控制表单的输出过程,实现自动化打印或显示。 5. **数据库表格**:这部分用于存储SAPscript中的文本、样式和表单数据。这些信息被保存在数据库中...

    abap演示例子矢志不渝

    abap演示例子abap演示例子abap演示例子abap演示例子abap演示例子

    SAP ABAP动态内表构建与例子

    在提供的例子中,"动态内表构建.pdf"和"动态内表例子.pdf"可能会展示如何在实际编程中创建和使用动态内表。这些示例通常包括创建内表、填充数据、遍历内表以及传递内表等步骤,对于理解动态内表的使用非常有帮助。...

Global site tag (gtag.js) - Google Analytics