2018 Feb 20 8:06 AM
Is there any way to create an object of a local class in program A in program B ?
REPORT Z_REPORT_A.
CLASS LCL_LOCAL_CLASS DEFINTION.
PUBLIC SECTION.
METHODS: say_foo.
ENDCLASS.
CLASS LCL_LOCAL_CLASS IMPLEMENTATION.
METHOD say_foo.
WRITE 'Foo from program Z_REPORT_A'.
ENDMETHOD.
ENDCLASS.
REPORT Z_REPORT_B.
Can I create an object of
LCL_LOCAL_CLASS
inZ_REPORT_B
??2018 Feb 20 8:46 AM
Horst once said: "You shouldn't do that but you can by using absolute type names."
hi
you can export/import object of class in one report to another report.
for this you have to use shared memory concept technique.
2018 Feb 20 8:12 AM
Not recommended! (see comments): You can put local class definition and implementation into the INCLUDE and use this include in both programs.
But it sounds it would be better to create global class? Reusability 🙂
2018 Apr 18 6:56 AM
2018 Apr 18 7:02 AM
Includes for re-use are indeed very very bad.
One project I was on decided to use an include in hundreds of BW routines. It all worked nicely until a change needed to be made... and 100s of BW flows had to be regenerated in production. Took quite a while.
The reason an include was used was the the outsourcing partner's staff weren't technically competent to do much beyond inserting include statements.
2018 Apr 18 7:04 AM
I remember a hotline issue with macros in mutliply used includes, arrgh ...
2018 Apr 18 7:42 AM
Edited, thank you.
It is true that I do not like debug through a lot of standard multiple used includes...
2018 Apr 18 7:21 PM
I believe this might come as a surprise to many long time ABAPers. Judging by the standard SAP code, at some point using the same INCLUDE in multiple places was The Thing. Personally, I haven't even heard that officially changed. I just happened to dislike INCLUDEs personally (especially those standard ones that tend to generate an annoying "what's the main program for this?" pop-up, ugh) and avoid them like plague. But I wouldn't have known it is a no-no these days to reuse them. Kind of thought that was their whole point... Huh. Well, that's my "learned something today". 🙂
2018 Apr 19 6:49 AM
Hmm, maybe if you read the ABAP Programming Guidelines (that were also published as a book about ten years ago) from beginning to end you'll find one or the other additional rule that you didn't know of 😉
2018 Apr 19 7:48 AM
At one time it was considered a nice way of organising code. There were even common memory areas - take the horror of global variables to a new level!
Back in pre-2000, there was a lot of bad practice programming. I guess we just didn't know it was bad practice - or maybe it was only known inside the ivory towers of academia. Now we know what's good and bad*. One of the beneficial side effects of the internet... 🙂
* For people who can be bothered to look. Apparently, some people still use prefixes to indicate the types of their variables. 😉
2018 Feb 20 8:30 AM
No you can't, the clue is in the word "Local". Use a global class.
It is however possible to use an instance of a local class elsewhere.
Also, do not use includes in multiple programs. https://help.sap.com/doc/abapdocu_751_index_htm/7.51/en-US/index.htm?file=abenmultiple_use_include_g...
2018 Feb 20 8:46 AM
Horst once said: "You shouldn't do that but you can by using absolute type names."
2018 Apr 18 5:49 AM
Is there any reason why we shouldn't use absolute type names ?
2018 Apr 18 6:58 AM
Yes. It's really bad programming. Likely to lead to hard to find (and therefore extremely expensive) bugs.
Why do you think you need to use local classes in this way?
2018 Apr 18 9:03 AM
It breaks encapsulation.
So, you shouldn't, but you can.
JNN
2018 Apr 18 7:25 PM
Better question to ask would be "why do I have to have some functionality that is implemented as local?" In this case, ask "why" not "why not".
2018 Feb 21 5:16 AM
hi
you can export/import object of class in one report to another report.
for this you have to use shared memory concept technique.
| User | Count |
|---|---|
| 6 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |