Quantcast
Channel: ABAP Development
Viewing all articles
Browse latest Browse all 948

A small debugger tip: Access static attribute in debugger

$
0
0

To illustrate the usage of this small tip, I write the following simple report.

 

cl_singleton is a simple singleton class. The single instance has one string table with two entries filled. The initialization is done in class a, method init.

 

The requirement is: in method do_something of class b, we need to check the variable mo_instance of class cl_singleton:

 

CLASS cl_singleton DEFINITION  CREATE PRIVATE .  PUBLIC SECTION.    CLASS-METHODS get_instance      RETURNING        VALUE(ro_instance) TYPE REF TO cl_singleton.    CLASS-METHODS class_constructor.  PRIVATE SECTION.    METHODS constructor.    CLASS-DATA mo_instance TYPE REF TO cl_singleton .    DATA: mt_data TYPE string_table.
ENDCLASS.
CLASS cl_singleton IMPLEMENTATION.  METHOD get_instance.    ro_instance = mo_instance.  ENDMETHOD.  METHOD constructor.    APPEND '1' TO mt_data.    APPEND '2' TO mt_data.  ENDMETHOD.  METHOD class_constructor.    CREATE OBJECT mo_instance.  ENDMETHOD.
ENDCLASS.
CLASS a DEFINITION.  PUBLIC SECTION.    CLASS-METHODS: init.
ENDCLASS.
CLASS a IMPLEMENTATION.  METHOD init.    DATA(lo_instance) = cl_singleton=>get_instance( ).  ENDMETHOD.
ENDCLASS.
CLASS b DEFINITION.  PUBLIC SECTION.    CLASS-METHODS: do_something.
ENDCLASS.
CLASS b IMPLEMENTATION.  METHOD do_something.    BREAK-POINT.  ENDMETHOD.
ENDCLASS.
START-OF-SELECTION.  a=>init( ).  b=>do_something( ).

For me as a CRM developer, this requirement is very common since from time to time in my trouble shooting I need to check the status of CL_CRM_BOL_CORE's singleton instance.

 

Back to this example, currently we are in execution context of class b, so neither mo_instance nor lo_instance can work in debugger.

 

clipboard1.png


instead, I have to manually type the string "{C:CL_SINGLETON}" and press enter in debugger, the variable type "CLASS" is then automatically determined.

clipboard2.png

Double click it, now the instance mo_instance of class CL_SINGLETON is accessible!

clipboard3.png

clipboard4.png

Hope this tip is helpful.


Viewing all articles
Browse latest Browse all 948

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>