Skip to Content
0
Former Member
Mar 30, 2015 at 12:40 PM

Assigning an object to other object?

15 Views

Hello all,

In the code below CALL METHOD w_o1->w_m2. is giving a syntax error w_m2. does not exist, actually this statement w_o1 = w_o3. just makes w_o1 to point to class c3 right?, and it wont create the object right? then how come CALL METHOD w_o1->w_m1 is working here?

CLASS c1 DEFINITION.

PUBLIC SECTION.

DATA:

w_v1 TYPE i.

METHODS:

w_m1 .

ENDCLASS. "c1 DEFINITION

CLASS c1 IMPLEMENTATION.

METHOD w_m1.

WRITE :/ 'Method m1 in Class c1'.

ENDMETHOD. "w_m1

ENDCLASS. "c1 IMPLEMENTATION

CLASS c2 DEFINITION INHERITING FROM c1.

PUBLIC SECTION.

DATA:

w_v2 TYPE i.

METHODS:

w_m2 .

ENDCLASS. "c2 DEFINITION

CLASS c2 IMPLEMENTATION.

METHOD w_m2.

WRITE :/ 'Method m2 in Class c2'.

ENDMETHOD. "w_v2

ENDCLASS. "c2 IMPLEMENTATION

CLASS c3 DEFINITION INHERITING FROM c2.

PUBLIC SECTION.

DATA:

w_v3 TYPE i.

METHODS:

w_m3 .

ENDCLASS. "c2 DEFINITION

CLASS c3 IMPLEMENTATION.

METHOD w_m3.

WRITE :/ 'Method m3 in Class c3'.

ENDMETHOD. "w_v2

ENDCLASS. "c2 IMPLEMENTATION

DATA:

w_o1 TYPE REF TO c1,

w_o3 TYPE REF TO c3.

START-OF-SELECTION.

CREATE OBJECT w_o3.

w_o1 = w_o3.

CALL METHOD w_o1->w_m1.

CALL METHOD w_o1->w_m2.