2007 Feb 19 4:33 AM
Hiya,
In SE80 class builder I have attribute R_OBJECT TYPE REF TO OBJECT.
In my CONSTRUCTOR method, I do a:
CREATE OBJECT R_OBJECT TYPE (lc_variable)
,where lc_variable contains type I want to use.
This seems to compile, but when I try to call a method using the following statement, the compiler complains saying that the method is not known. Well, of course it's not known, I haven't told it which class the object belongs to yet!
CALL METHOD R_OBJECT->MY_METHOD RECEIVING lc_result.
What am I doing wrong?
Thanks,
Tristan
2007 Feb 19 10:59 AM
Hello Tristan
The <b>static</b> type of r_object is OBJECT and, therefore, will never have any methods you have defined. In order to call your method you must do <b>narrow casting</b>, e.g:
DATA:
lo_myclass TYPE REF TO <lc_variable>. " your class
CREATE OBJECT R_OBJECT TYPE (lc_variable).
* Narrow casting required
lo_myclass ?= r_object.
lc_result = lo_myclass->my_method( ). " now it worksRegards
Uwe
Hiya,
In SE80 class builder I have attribute R_OBJECT TYPE REF TO OBJECT.
In my CONSTRUCTOR method, I do a:
CREATE OBJECT R_OBJECT TYPE (lc_variable)
,where lc_variable contains type I want to use.
This seems to compile, but when I try to call a method using the following statement, the compiler complains saying that the method is not known. Well, of course it's not known, I haven't told it which class the object belongs to yet!
CALL METHOD R_OBJECT->MY_METHOD RECEIVING lc_result.
What am I doing wrong?
Thanks,
Tristan
2007 Feb 19 10:59 AM
Hello Tristan
The <b>static</b> type of r_object is OBJECT and, therefore, will never have any methods you have defined. In order to call your method you must do <b>narrow casting</b>, e.g:
DATA:
lo_myclass TYPE REF TO <lc_variable>. " your class
CREATE OBJECT R_OBJECT TYPE (lc_variable).
* Narrow casting required
lo_myclass ?= r_object.
lc_result = lo_myclass->my_method( ). " now it worksRegards
Uwe