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: 

dynamic class loading and abap_parmbind

Former Member
0 Kudos
1,106

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

3 REPLIES 3

Former Member
0 Kudos
610

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ü

0 Kudos
610

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

0 Kudos
425

Hello Sukru, 

Could you please tell me what exactly the kind 'E' refers to in this,

ls_parmbind-kind = 'E'.