Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Call method from an other program

Former Member
0 Kudos

Hi,

Please is there a way to call and use a method declared in an other program.

Thanks for your help.

Issam.

5 REPLIES 5

uwe_schieferstein
Active Contributor
0 Kudos

Hello Issam

If you are talking about local classes defined within a program then the answer is most likely not.

Perhaps if the program containing the local classes calls your report you may try the "...Love User-Exits..." trick:

[SAP User Exits and the People Who Love Them|https://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/208811b0-00b2-2910-c5ac-dd2c7c50c8e8]

Regards

Uwe

Former Member
0 Kudos

Thanks Uwe,

I will try this , though I never use the USER EXIT. I have work with BADI I don't if this help me out,

Thank u for your help.

Issam

Former Member
0 Kudos

Hi Issam,

In ABAP, there are 2 ways of defining Repository Objects. 1. Local Objects and 2. Global Objects.

While you can define local objects (eg.local classes,data types) and those will be available in the local context of that Object. (Except few Objects like Subroutines - you can call a subroutine of one report program from another report).

But, if you want to use objects across application, you need to define them Globally. There are certain advantages of defining it globally for example Object Maintainence will be easy.

So, generally a method defined in one local class will not be available in another class.

Hope this helps.

Thanks,

Samantak.

Former Member
0 Kudos

Hello Issam,

it is possible, but in my opinion it is not recommended. Classes which are used over multiple programs should be implemented in class pools and not in local classes. Local classes may have dependencies to their context (e.g. through the usage of a global variable in the surrounding program). Using them from outside this context is potentially dangerous.

Nevertheless, here is a simple example how to use a local class of another program:

Program 1 - contains the local class:


REPORT y_test_prog1.

CLASS lcl_local_class DEFINITION.
  PUBLIC SECTION.
    METHODS foo.
ENDCLASS.

CLASS lcl_local_class IMPLEMENTATION.
  METHOD foo.
    WRITE 'Foo.'.
  ENDMETHOD.
ENDCLASS.

Program 2 - uses the class LCL_LOCAL_CLASS from program 1:


REPORT y_test_prog2.

DATA: go_test TYPE REF TO object,
      ge_abs_typename TYPE string VALUE
                        `\PROGRAM=Y_TEST_PROG1\CLASS=LCL_LOCAL_CLASS`.

START-OF-SELECTION.
  CREATE OBJECT go_test TYPE (ge_abs_typename).
  CALL METHOD go_test->('FOO').                    " writes 'Foo.'

Regards,

David

Former Member