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: 
Read only

Dynamic programming accessing static method on classes

Former Member
0 Likes
2,238

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

3 REPLIES 3
Read only

Former Member
0 Likes
1,085

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.

Read only

0 Likes
1,085

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

Read only

uwe_schieferstein
Active Contributor
0 Likes
1,085

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