2010 Sep 27 11:10 AM
Hi,
The following code snippet does not work. How can i declare the variable lo_content so that
i can achieve the object creation based on class availability.
********************************************************************************
DATA:
lo_content TYPE REF TO data .
if class 'cl_ap_a2x_service_manager' exists.(using a FM SEO_CLASS_GET)
CREATE OBJECT lo_content TYPE ('cl_ap_a2x_service_manager').
endif.
********************************************************************************
I cannot declare it as: lo_content TYPE REF TO cl_ap_a2x_service_manager .
I will not allow to activate the code as class cl_ap_a2x_service_manager doesnot exist in the same system.
Regards,
Bikash.
2010 Sep 27 11:32 AM
You are mixing data references (type ref to DATA) with object references (type ref to OBJECT). The latter should be used in this case (so that any object type can be stored in this reference, not any data ).
DATA:
lo_content TYPE REF TO object .
CREATE OBJECT lo_content TYPE ('CL_AP_A2X_SERVICE_MANAGER').
Regards
Marcin
2010 Sep 27 11:20 AM
Check this:
DATA:
lo_content TYPE REF TO data .
if class 'cl_ap_a2x_service_manager' exists.(using a FM SEO_CLASS_GET)
CREATE DATA lo_content TYPE REF TO ('CL_ABAP_STRUCTDESCR').
endif.
2010 Sep 27 11:32 AM
You are mixing data references (type ref to DATA) with object references (type ref to OBJECT). The latter should be used in this case (so that any object type can be stored in this reference, not any data ).
DATA:
lo_content TYPE REF TO object .
CREATE OBJECT lo_content TYPE ('CL_AP_A2X_SERVICE_MANAGER').
Regards
Marcin
2010 Sep 27 11:41 AM
>
> You are mixing data references (type ref to DATA) with object references (type ref to OBJECT). The latter should be used in this case (so that any object type can be stored in this reference, not any data )
Hey Marcin,
I was about to correct my post Anyway today i had my first experience with generic object reference variable (OBJECT) !!
DATA:
lo_content TYPE REF TO object,
it_bdc_msg TYPE ZLMT_LINE.
FIELD-SYMBOLS: <attr> TYPE ANY.
CREATE OBJECT lo_content TYPE ('ZCL_CALL_TRANSACTION')
EXPORTING IM_TRANSACTION = 'SE11'.
CALL METHOD lo_content->('GET_BDC_MESSAGES')
RECEIVING RE_BDC_MESSAGES = it_bdc_msg.
Cheers,
Suhas
2010 Sep 27 11:49 AM
No worries Suhas
One thing I would like to point at. I think these two statements are syntatically incorrect
CREATE OBJECT lo_content TYPE ('ZCL_CALL_TRANSACTION')
EXPORTING IM_TRANSACTION = 'SE11'.
CALL METHOD lo_content->('GET_BDC_MESSAGES')
RECEIVING RE_BDC_MESSAGES = it_bdc_msg.
This is because you are providing the class/method name dynamically, but its interface statically. Syntax checker will not recognize this signature as a valid one, unless it knows the name of class/method it is reffering to - as this comes during runtime, the interface parameters must also be provided dynamically.
Cheers
Marcin
PS: I just spotted in one of my programs that I was wrong with the above statement. Interface can be statical even class/method is provided dynamically. It is similar to calling FM where we deliver its name dynamically but interface is static. Sorry for this confusion
Edited by: Marcin Pciak on Sep 27, 2010 1:00 PM