Skip to Content
avatar image
-2
Former Member

How to get all class elements?

Hello,

How to get all elements from class.

I want to clear all global variables. But I don't know, how I get all global elements from my Abap class.

I hope, you could help me.

Add comment
10|10000 characters needed characters exceeded

  • Your question is bit poor. Rather than ask how to implement your chosen solution to the programming problem, you should explain what you are trying to achieve in general. Then you may get other solutions that are better than your preferred one (dynamic clearing of static attributes, it seems). Furthermore, it means people don't have to guess at your intentions, thereby increasing the quality of the answers.

  • Get RSS Feed

5 Answers

  • Aug 15, 2017 at 12:31 PM

    I'd just create a new reference, let the garbage collector do the rest for you...

    (after clearing all public and private variables the whole class is initial, isn't it? Or am I missing something?)

    Add comment
    10|10000 characters needed characters exceeded

    • It was a joke. You assumed he meant static, but if someone inaccurately calls attributes global, which they clearly aren't (as I said in my first response), then they would not necessarily have the same view.

      If we try to define the globularity (globulosity?) of scope vs lifetime, one could argue that that which is visible to the outside looks 'global', making a public 'more global' than a private static, even though it has a shorter lifetime.

      But, just in case someone draws any conclusions, all of this is nonsense of course :-)

  • Aug 15, 2017 at 12:56 PM

    @OP: What is your motivation for clearing the attributes of the instance?

    Add comment
    10|10000 characters needed characters exceeded

  • Aug 15, 2017 at 08:27 AM

    CL_ABAP_CLASSDESCR

    Loop over the attribute table, dynamic assign to field symbol (attribute must be visible), CLEAR field symbol.

    Add comment
    10|10000 characters needed characters exceeded

  • Aug 15, 2017 at 10:16 AM

    If you mean how to clear all statics in a class - write a method to do it and call that.

    Add comment
    10|10000 characters needed characters exceeded

    • Clearing all the static attributes of a class indicates that your design is poor. I can't see why the complexity of doing it dynamically could be preferable. I've never written a class where this was needed, and I've written thousands.

      Consider using the singleton pattern instead. Then you can have a static method that creates and new instance, and returns that (clearing the old one).

  • Aug 15, 2017 at 08:27 AM

    An ABAP class doesn't have any global variables. All attributes are local to the class.

    RTTI services can provide you all components of a class, use CL_ABAP_CLASSDESCR.

    Add comment
    10|10000 characters needed characters exceeded