2004 Jun 07 2:58 PM
Hello,
I am using dynamic class loading with a
CREATE OBJECT obj TYPE (<classname>)
PARAMETER-TABLE <param_table>
statement. The objects I am trying to create have a constructor which expect a parameter called 'model' of type ref to cl_bsp_model, i.e. a simple object reference.
Now, as the structure of the parameter table is abap_parmbind, the value of a parameter needs to be of type ref to data - that is not a object reference.
How can I transfer my model object now to the class' constructor?
To put it more general: how can one transfer constructor parameters in dynamic class loading, when the parameters are not simple types (but references)?
Regards,
Sebastian Kamp
2004 Jun 09 6:44 PM
Hello Sebastian,
You can take the reference of the object to a data reference variable using command GET REFERENCE OF lv_object_ref INTO lv_data_ref.You can find a small program as an example below.I hope it helps.
REPORT YREF_TEST.
TYPE-POOLS: abap.
DATA: ls_parmbind TYPE abap_parmbind,
lt_parmbind LIKE HASHED TABLE OF ls_parmbind
WITH UNIQUE KEY name.
*----
*
CLASS lcl_test DEFINITION
*----
*
*
*----
*
CLASS lcl_test DEFINITION.
PUBLIC SECTION.
DATA: av_int TYPE i VALUE 4 READ-ONLY.
ENDCLASS. "lcl_test DEFINITION
*----
*
CLASS lcl_main DEFINITION
*----
*
*
*----
*
CLASS lcl_main DEFINITION.
PUBLIC SECTION.
METHODS: constructor
IMPORTING iv_obj TYPE REF TO lcl_test.
DATA: av_main_int TYPE i.
ENDCLASS. "lcl_main DEFINITION
*----
*
CLASS lcl_main IMPLEMENTATION
*----
*
*
*----
*
CLASS lcl_main IMPLEMENTATION.
METHOD constructor.
av_main_int = iv_obj->av_int.
write av_main_int.
ENDMETHOD. "constructor
ENDCLASS. "lcl_main IMPLEMENTATION
START-OF-SELECTION.
DATA: lv_dref TYPE REF TO data.
DATA: lv_objref TYPE REF TO lcl_test,
lv_obj_dynref TYPE REF TO object,
lv_class_name TYPE string.
CREATE OBJECT lv_objref.
GET REFERENCE OF lv_objref INTO lv_dref.
lv_class_name = 'LCL_MAIN'.
ls_parmbind-name = 'IV_OBJ'.
ls_parmbind-kind = 'E'.
ls_parmbind-value = lv_dref.
INSERT ls_parmbind INTO TABLE lt_parmbind.
CREATE OBJECT lv_obj_dynref TYPE (lv_class_name)
PARAMETER-TABLE lt_parmbind .
Regards,
Sükrü
2004 Jun 10 12:54 PM
Hello Sükrü,
thanks for your answer. I had tested a variant of your solution, but it did not work and I think I know why.
The GET REFERENCE OF command will return a data reference to the variable - regardless of the type of this variable. If the variable is an object reference itself, the GET REFERENCE will return a data reference to this reference and not the actual object.
Regards,
Sebastian
2024 Oct 07 6:06 PM
Hello Sukru,
Could you please tell me what exactly the kind 'E' refers to in this,
ls_parmbind-kind = 'E'.