‎2010 Apr 17 7:55 AM
Hi
I need access to a static method on a class.
The class name is first decided at runtime.
How do I do that?
Regards,
Morten
‎2010 Apr 17 9:14 AM
Hey Good day,
Check out this link you might get exact answer for it.
http://www.abaplearning.com/abap-tutorials/dynamic-programming/37-dynamic-method-calls-in-abap
Regards and Best wishes.
‎2010 Apr 17 9:48 AM
Hi,
Thanks for the reply.
I can see how to create a dynamic object type but not how to call a static method.
CLASS_NAME=>create_instance( ).
This is the part I am seaching for.
Regards,
Morten
‎2010 Apr 17 11:36 AM
Hello Morten
Here is a sample program for you:
*&---------------------------------------------------------------------*
*& Report ZUS_SDN_DYNAMIC_METHOD_CALL
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT zus_sdn_dynamic_method_call.
DATA: go_msglist TYPE REF TO if_reca_message_list.
DATA: gd_method TYPE tmdir-methodname,
gd_class TYPE seoclsname.
START-OF-SELECTION.
IF ( 1 = 2 ).
CALL METHOD cf_reca_message_list=>create
* EXPORTING
* id_object = 'RECA'
* id_subobject = 'MISC'
* id_extnumber =
RECEIVING
ro_instance = go_msglist.
go_msglist = cf_reca_message_list=>create( ).
ENDIF.
gd_class = 'CF_RECA_MESSAGE_LIST'.
gd_method = 'CREATE'.
CALL METHOD (gd_class)=>(gd_method)
RECEIVING
ro_instance = go_msglist.
IF ( go_msglist IS BOUND ).
WRITE: / 'Class is bound'.
ELSE.
WRITE: / 'Class is NOT bound'.
ENDIF.
END-OF-SELECTION.
Obviously, that is only half of the task. You need to make the method signature dynamically as well.
Regards
Uwe