2012 Jan 17 1:15 PM
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
2012 Jan 17 2:31 PM
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
2012 Jan 17 2:31 PM
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
2012 Jan 18 7:31 AM
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
2012 Jan 19 7:35 AM
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