ABAP Debugging Script(调试器脚本)使用的一些实际例子-阿里云开发者社区

开发者社区> c位出道> 正文

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

简介: 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:


image.png(2) double click DATA_REF:image.png(3) double click:image.png(4) double click ATTRIBUTE_REF:image.png(5) double click:image.pngSo totally you need to perform FIVE times double click in order to review content:image.png

Using ABAP debugger script

(1) Click Script tab:

image.png(2) Create a new script:image.pngChoose a name for your script:image.png(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 IMPLEMENTATIONOnce done, save the script and choose “Execute Directly”.

image.png(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”.


image.pngOnce done, click button “Start Script”:

the BOL entity content is now automatically displayed, without five times double click any more.image.png例子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:


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

image.pngWe need the following FIVE steps to see the selection parameter value.

(1) double click SELECTION_PARAM_COL:image.png(2) Double click ENTITY_LIST:

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

image.png(4) Double click PARAMETER_DATA:image.png(5) double click:

image.png

Finally we see the value:

image.png


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

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


image.png(2) Choose a name for your script:image.pngPaste 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 IMPLEMENTATIONSpecify the name of your query service variable in line 21. In my example, it is QS.

Start script by clicking button “Start Script”:

image.pngNow you see all four selection parameter value displayed in ALV.image.png

版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。

相关文章
Shell脚本单实例运行|学习笔记
快速学习Shell脚本单实例运行
45 0
javascript:使用document.getElementById读取数据为空分析
  今天写个网页,想在页面加载onLoad时,动态显示由后台其他程序传来的数据时,用document.getElementById获取控件对象总是为空。但是检查了这个id确实是存在的。在网上查阅一番后才知道了其中的原因。
892 0
javascript使用栈结构将中缀表达式转换为后缀表达式并计算值
1.概念   你可能听说过表达式,a+b,a+b*c这些,但是前缀表达式,前缀记法,中缀表达式,波兰式,后缀表达式,后缀记法,逆波兰式这些都是也是表达式。   a+b,a+b*c这些看上去比较正常的是中缀表达式,就是运算符放在两个操作数之间。
1113 0
JavaScript正则使用点滴
写在前面:关于“railroad diagrams”,摘抄自网络:http://202.207.0.245:9001/jisuanjifazhanshi/tuling/19.htm     我们目前所看到的许多语言的BNF实际上是EBNF,不过人们往往忽略掉这个E字。
607 0
JavaScript使用原型判断对象类型
1. constructor属性 在JavaScript创建对象(二)——构造函数模式中,我们说过可以使用对象的constructor属性判断对象的类型:p1.constructor === Person,可能当时就有细心的读者会想,我们并没有给这个对象添加过constructor,这个属性是从哪儿来的呢?讲过原型之后,我们知道这个属性是原型中的,所以一般重写原型时也都会把constructor补上。
1134 0
+关注
2316
文章
0
问答
来源圈子
更多
+ 订阅
文章排行榜
最热
最新
相关电子书
更多
《2021云上架构与运维峰会演讲合集》
立即下载
《零基础CSS入门教程》
立即下载
《零基础HTML入门教程》
立即下载