Copyright 2024 - BV TallVision IT

Can a locally defined method be called from an external program ? Could be useful if you are preparing software components that require easy installation and external calls are also a requirement. Here's how.

Let's assume we have a class that is defined and implemented as LCL_MYCLASS in a report called ZABAPCADABRA_TEST. The method to be called is WRITER and it requires no parameters. Simply implement the call from your own program like this:

CALL METHOD ('\PROGRAM=ZABAPCADABRA_TEST\CLASS=LCL_MYCLASS')=>('WRITER'). 

Make sure the method is a PUBLIC SECTION. method, which is also defined as CLASS METHODS.

If you do want parameters to be passed, simply add them to the call. And if the method you're after is not a class method but an instance method, you will have to take things a bit further. First create a variabele with type definition

REPORT ZABAPCADABRA_TEST.

CALL METHOD ('\PROGRAM=ZABAPCADABRA_TEST\CLASS=LCL_MYCLASS')=>('WRITER').

CALL METHOD ('\PROGRAM=ZABAPCADABRA_TEST\CLASS=LCL_MYCLASS')=>('WRITER')
  EXPORTING something = 'Howz it all going"? '.

* To access an instance method:
data: go_object type ref to object.
CREATE OBJECT go_object TYPE ('\PROGRAM=ZABAPCADABRA_TEST\CLASS=LCL_MYCLASS').
CALL METHOD go_object->('WRITING_MORE').

class lcl_myclass definition.
  public section.
  class-methods:
    writer importing something type string default space.
  methods:
    writing_more.
endclass.

class lcl_myclass IMPLEMENTATION.
  method writer.
    write: /,/ 'Hello there !', / something, / sy-uline(25).
  endmethod.

  method writing_more.
    write: /,/ 'More..'.
  endmethod.
endclass.

The output of this report looked like this:

Hello there !
-------------------------------------

Hello there !
Howz it all going"?
-------------------------------------

More..

The above example calls the class method WRITER and method WRITING_MORE in a rather unusual manner. The class definition and methods can reside in an external source, even though in the example they reside in the same source. So you can create an instance of a class which is defined in an external program. This can be a very effective way to confuse the ..*.. out of people like yourself. Don't use it.

There is one way I can think if where the feature can be quite handy. This site holds a lot of "ready to run" reports that are very easy to install. Simply copy the coding into an abap report, and start it. This type of "turn-key" programming can be a means to allow connecting easily. An external call to a method in the "turn key" report - can be quite useful. Having said that: I can not think of any other times this feature would have been a help.