‎2012 Nov 08 4:20 AM
This may be a silly question to some.. but..
I have put a simple local class definition and implementation into the "Local Definitions/Implementations" section of my global class (SE24). However I am unable to reference this local class *anywhere* in my global class. According to what 'little' documentaiton I can find on this, the local class should be accessible within the global class. My local class is just called lcl_model. If I try to reference it with: "data mr_model type ref to lcl_model." it raises an error that "lcl_model is unknown" (tried in private, protected and public sections). I've also tried various friend attributes in the local definitions include to no avail.
Any ideas? Surely it's something silly...
Regards, Jason.
‎2012 Nov 08 4:46 AM
You can access it in the method implementations and not in declaration of a method parameter( importing/exporting/changing). Please check if the local definitions is activated properly. It works for me.
‎2012 Nov 08 4:46 AM
You can access it in the method implementations and not in declaration of a method parameter( importing/exporting/changing). Please check if the local definitions is activated properly. It works for me.
‎2012 Nov 08 5:00 AM
Thanks for the reply - you're correct - I can reference the class INSIDE a method but I cannot reference it in a class attribute nor in the parameter interface of any method.
I was trying to set my class up to allow dependacy injection for testing but its looking like thats just not possible with abap-oo in this case as I need to be able to pass in a reference to the local class to the method.
i.e. put my select statements into a local class which can be replaced with a test double in unit-tests.
‎2012 Nov 08 8:33 AM
Hi Jason,
it´s correct - local class definitions are not accesible from outside their surrounding class. I think this makes sense because otherwise the class would be global. Although, e. g. Java offers more possibilities here...
For your problem I would suggest to define a global interface which the parameter is typed to. Then you can have a local implementation (e. g. if the parameter is not filled) and the caller can produce it´s own implementation.
Btw.: Whe don´t you implement your Unit Test as a local class of the test class?
Local testclasses and Interfaces for used objects is btw. our best practice.
Regards,
Stefan
‎2012 Nov 08 1:18 PM
Thanks Stefan. The code I'm speaking of is not the actual test code. I'll use local test classes for that of course.
I think I'll switch to global classes and interfaces as you've suggested as local classes inside a global class are too limited. Thankyou.
‎2012 Nov 08 1:33 PM
‎2012 Nov 08 1:36 PM
The Jive iPhone app won't let me do anything except like and reply. Next time I look at this on the full website I'll close it out...
‎2012 Nov 09 10:30 AM
‎2024 Sep 23 2:47 PM
You can of course use local classes for attributes in your global class, e.g.
data mo_substitution type ref to lcl_substitution.You have to define them in the separate tab "Class-relevant Local Types" in Eclipse. In SAPGUI, you can access it via menu only: Goto / Local Definitions / Class relevant local definitions