1

In the program e1 is class event and c1 a class method. I tried calling class event using invocation for class methods c1=>t1 and invocation for object methods c1->t1 and both are successful. why? As we know class methods are always called by c1=>t1.

REPORT  my_event7.
CLASS c1 DEFINITION.
  PUBLIC SECTION.
    CLASS-EVENTS: e1.
    METHODS: m1 FOR EVENT e1 OF c1.
    CLASS-METHODS : t1.
ENDCLASS.                    "c1 DEFINITION

CLASS c1 IMPLEMENTATION.
  METHOD : t1.
    WRITE:/5 'C1->T1'.
    RAISE EVENT e1.
  ENDMETHOD.                   
  METHOD : m1.
    WRITE:/5 ' C1->M1'.
  ENDMETHOD.                    ":
ENDCLASS.                    "c1 IMPLEMENTATION

CLASS c2 DEFINITION.
  PUBLIC SECTION.
    METHODS: m2 FOR EVENT e1 OF c1.
ENDCLASS.                    "c2 DEFINITION

CLASS c2 IMPLEMENTATION.
  METHOD : m2.
    WRITE:/5 ' C2->M2'.
  ENDMETHOD.                    
ENDCLASS.                  "c2 IMPLEMENTATION

START-OF-SELECTION.
  DATA: oref1 TYPE REF TO c1.
  DATA: oref2 TYPE REF TO c2.
  CREATE OBJECT: oref1 .
  CREATE OBJECT: oref2 .
  SET HANDLER oref1->m1 oref2->m2.
  CALL METHOD c1=>t1.
  CALL METHOD oref1->t1.
gram77
  • 361
  • 1
  • 12
  • 30
  • `Class methods are always called by c1=>t1.` - No - as you can see. Let's call it syntactical sugar that you can use also `->`. – knut Sep 14 '15 at 07:23
  • What is the actual question here? – vwegert Sep 14 '15 at 07:29
  • @vwgert: we are discussing about calling calss methods with a call notation ClassObject->ClassMethod. Which should be Class=>ClassMethod. Thanks. – gram77 Sep 14 '15 at 07:38

1 Answers1

3

You may call it syntactical sugar.

Class methods can be called without any instance with <classname>=>method.

But you can also call the class method via the instance of the class. And then you can use the normal method call with ->. But in background the class method is called.

knut
  • 27,320
  • 6
  • 84
  • 112
  • [This is the case for other languages as well...](http://stackoverflow.com/questions/610458/why-isnt-calling-a-static-method-by-way-of-an-instance-an-error-for-the-java-co) – vwegert Sep 14 '15 at 07:34