Skip to Content

Local class # Object creation from another program

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

in

Z_REPORT_B

??
Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

4 Answers

  • Best Answer
    Feb 20 at 08:46 AM

    Horst once said: "You shouldn't do that but you can by using absolute type names."

    Add comment
    10|10000 characters needed characters exceeded

  • Feb 20 at 08: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 :)

    Add comment
    10|10000 characters needed characters exceeded

    • 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. ;-)

  • Feb 20 at 08: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_guidl.htm

    Add comment
    10|10000 characters needed characters exceeded

  • Feb 21 at 05:16 AM
    -5

    hi

    you can export/import object of class in one report to another report.

    for this you have to use shared memory concept technique.

    Add comment
    10|10000 characters needed characters exceeded