Application Development 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 call of a static method of an static attribute

Former Member
0 Kudos
598

Hi all,

is it possible to call dynamically a static method of a static attribute of a class.

The statement without dynamic call would look like this:

cl_test_class=>static_attribute=>static_method( ).

I would like to do it like this:

('CL_TEST_CLASS')=>static_attribute=>static_method( ).

Netiher the one nor the other way works for me - I'm getting the error "The notation used is reserved for business object classes".

Regards, Stefan

1 ACCEPTED SOLUTION

naimesh_patel
Active Contributor
0 Kudos
175

I guess, it is not possible to call method using the short form (parameters in brackets) is not possible in Dynamic Access. You may need to get the attribute first and then call the method.


CLASS lcl_main DEFINITION.
  PUBLIC SECTION.
    CLASS-DATA: o_same TYPE REF TO lcl_main.
    METHODS: run.
ENDCLASS.                    "lcl_main DEFINITION
*
CLASS lcl_main IMPLEMENTATION.
  METHOD run.
    WRITE: 'success'.
  ENDMETHOD.                    "run
ENDCLASS.                    "lcl_main IMPLEMENTATION

START-OF-SELECTION.
  DATA: lo_same TYPE REF TO lcl_main.
  CREATE OBJECT lcl_main=>o_same.

*  lcl_main=>o_same=>run( ).
  TRY.
      FIELD-SYMBOLS: <fs> TYPE REF TO lcl_main.
      ASSIGN ('LCL_MAIN')=>('O_SAME') TO <fs>.
      CALL METHOD <fs>->('RUN').
    CATCH cx_root.
  ENDTRY.

Regards,

Naimesh Patel

3 REPLIES 3

naimesh_patel
Active Contributor
0 Kudos
176

I guess, it is not possible to call method using the short form (parameters in brackets) is not possible in Dynamic Access. You may need to get the attribute first and then call the method.


CLASS lcl_main DEFINITION.
  PUBLIC SECTION.
    CLASS-DATA: o_same TYPE REF TO lcl_main.
    METHODS: run.
ENDCLASS.                    "lcl_main DEFINITION
*
CLASS lcl_main IMPLEMENTATION.
  METHOD run.
    WRITE: 'success'.
  ENDMETHOD.                    "run
ENDCLASS.                    "lcl_main IMPLEMENTATION

START-OF-SELECTION.
  DATA: lo_same TYPE REF TO lcl_main.
  CREATE OBJECT lcl_main=>o_same.

*  lcl_main=>o_same=>run( ).
  TRY.
      FIELD-SYMBOLS: <fs> TYPE REF TO lcl_main.
      ASSIGN ('LCL_MAIN')=>('O_SAME') TO <fs>.
      CALL METHOD <fs>->('RUN').
    CATCH cx_root.
  ENDTRY.

Regards,

Naimesh Patel

0 Kudos
175

Hi Naimesh Patel,

thank you for your reply. I think your implementation would solve my problem, but unfortunately I can not define this variable:

FIELD-SYMBOLS: <fs> TYPE REF TO lcl_main.

The local class is a private local type. Is there a way to solve this issue?

Regards, Stefan

0 Kudos
175

Also if my question was not answered completely, I found a workaround via the meta-data of the object. Unfortunately it's to special to post it here.

Thanks & best regards, Stefan