‎2007 Sep 20 3:56 AM
we called the static method CL_ABAP_CLASSDESCR=>DESCRIBE_BY_NAME( '<class_name>' ).
The method returns an instance of CL_ABAP_CLASSDESCR, the instance name is l_object.
l_object = cl_abap_classdescr=>describe_by_name( class_name ).
We had already know that in this class(class_name), it has a Public method GET_INSTANCE(), then
call method l_object->get_instance
RECEIVING
return = l_objectXX.
but error shows: Method "GET_INSTANCE" is unknown or PROTECTED or PRIVATE. then how to use the l_object to call this method dynamically??
‎2007 Sep 20 4:06 AM
The class_name here is dynamic, the value is passed by other program. so the methods of the different class_name are dynamic as well. that is why we can not use create object obj type class_name here.
‎2007 Sep 20 8:23 AM
currently, we use below codes to realize this, but
DATA:
l_parameters TYPE abap_parmbind_tab,
l_parameter_wa TYPE abap_parmbind,
l_class_param_wa TYPE swcont,
l_descr_ref TYPE REF TO cl_abap_classdescr,
l_constructor TYPE abap_methdescr,
l_constructor_param TYPE abap_parmdescr.
FIELD-SYMBOLS: <g>.
DATA: lv_ref1 TYPE REF TO cl_abap_classdescr.
DATA: lv_ref TYPE REF TO object.
DATA: lv_ref2 TYPE REF TO object.
gv_class = "class_name ".
lv_ref1 ?= cl_abap_typedescr=>describe_by_name( gv_class ).
l_parameter_wa-name = 'RETURN'.
l_parameter_wa-kind = cl_abap_classdescr=>exporting.
INSERT l_parameter_wa INTO TABLE l_parameters.
CREATE OBJECT lv_ref
TYPE
(gv_class)
PARAMETER-TABLE
l_parameters.
CALL METHOD lv_ref->('GET_INSTANCE')
receiving
return = lv_ref2.
but when create the object, error shows:
CREATE OBJECT is not permitted for this class at this point. It was tried to create an instance of the class "CL_HRRCF_CANDIDATE_BUPA_BL".
This class is declared as 'CREATE PRIVATE', which means that the 'CREATE' for this class is 'private', that means, creating intances of this class is only allowed within the class (in the methods of the class), but not outside.
Can anyone help me on this? thnak very much!