‎2008 Apr 09 1:01 PM
hi all,
We update our SAP from 4.7 to ECC6.0 and now, in a report program it's giving the next error:
- You cannot create an instance of the class "CL_SWF_REP_MANAGER" outside the class...
at 4.7 it's work fine.
here it's the code:
CLASS cl_swf_rdg_dispatcher DEFINITION LOAD.
DATA: int TYPE REF TO if_swf_rep_workitem_selection.
{ ... }
IF int IS INITIAL.
CREATE OBJECT int TYPE cl_swf_rep_manager.
ENDIF.
{ ... }
Thanks for ur help.
‎2008 Apr 09 3:22 PM
Hi Alan,
We usually define the class as PROTECTED or PRIVATE to avoid direct access and Final to avoid INHERITING. Thus you must use the method GET_INSTANCE to get a instance of its class.
Use this way:
DATA o_ref_class TYPE REF TO cl_swf_rep_manager.
DATA o_ref_interf TYPE REF TO if_swf_rep_workitem_selection.
START-OF-SELECTION.
*// Instantiate your object using Norrowing cast
o_ref_class ?= cl_swf_rep_manager=>get_instance( ).
*// Instantiate your object using Widening cast
o_ref_interf = cl_swf_rep_manager=>get_instance( ).
Don't forget to close this Thread when your question be answered !
Best Regards.
Marcelo Ramos
‎2008 Apr 09 1:21 PM
Hello,
This occurs because now the instantiation method for the class is private (folder Properties ), that is, the only way to instantiate the class is using a friend/agent to instantiate the class. The agents are declared as friends of the class, go to the folder Friends and you will find the class CL_SWF_REP_ITEM2OBJECT. Now you need to change the reference variable to refer to this friend class/interface with instantion method public and find out in this one how to instantiate the class.
Regards,
‎2008 Apr 09 3:22 PM
Hi Alan,
We usually define the class as PROTECTED or PRIVATE to avoid direct access and Final to avoid INHERITING. Thus you must use the method GET_INSTANCE to get a instance of its class.
Use this way:
DATA o_ref_class TYPE REF TO cl_swf_rep_manager.
DATA o_ref_interf TYPE REF TO if_swf_rep_workitem_selection.
START-OF-SELECTION.
*// Instantiate your object using Norrowing cast
o_ref_class ?= cl_swf_rep_manager=>get_instance( ).
*// Instantiate your object using Widening cast
o_ref_interf = cl_swf_rep_manager=>get_instance( ).
Don't forget to close this Thread when your question be answered !
Best Regards.
Marcelo Ramos
‎2008 Apr 09 3:41 PM
You'll often see methods such as GET_INSTANCE referred to as factory methods.
matt