Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

error creating a object

Former Member
0 Likes
2,668

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.

1 ACCEPTED SOLUTION
Read only

marcelo_ramos1
SAP Mentor
SAP Mentor
1,268

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

3 REPLIES 3
Read only

Former Member
0 Likes
1,268

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,

Read only

marcelo_ramos1
SAP Mentor
SAP Mentor
1,269

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

Read only

matt
Active Contributor
0 Likes
1,268

You'll often see methods such as GET_INSTANCE referred to as factory methods.

matt