abap

How to read a private attribute of an object without a getter in ABAP


Is there any way to get the value of an objects' private attribute without a getter. Modifying the class is not permitted in any shape or form.

Please find below an example class with a private attribute.

CLASS counter DEFINITION.
  PUBLIC SECTION.
    METHODS: set IMPORTING value(set_value) TYPE i.
  PRIVATE SECTION.
    DATA count TYPE i.
ENDCLASS.                    "counter DEFINITION 

CLASS counter IMPLEMENTATION.
  METHOD set.
    count = set_value.
  ENDMETHOD.                    "set
ENDCLASS.                    "counter IMPLEMENTATION

How can I get the value of count? Inheriting from counter will not work because count is private, not protected.


Solution

  • Unfortunately not, I have tried this myself in many different ways none of which work:

    • Having a standard super class - the super class cannot access the
      private attributes of subclasses dynamically
    • Making a subclass will never work since it can only access protected
    • Attempting to use the unit test framework doesn't work. I tried to call the kernel modules that allow access to private data but to no avail.

    You are basically flat out of luck. There is one obscure option though depending on the class you are trying to access. Some classes have interfaces specified as friends and if you implement that interface you can access their private data (the ALV on 7.20 is like this) but unfortunately this will only work in a few limited cases.