I try to demonstrate a CALL METHOD statement with dynamic method name on a 7.40 system. I use the following test code and get an ABAP Runtime Error in line 27. The Error Analysis in the Description of Exception states ... in the class LCL, the method "m" could not be found. But the standalone method call succeeds in calling m.
REPORT ZUTEST10.
CLASS lcl DEFINITION.
PUBLIC SECTION.
METHODS m.
ENDCLASS.
CLASS lcl IMPLEMENTATION.
METHOD m.
write / 'success'.
ENDMETHOD.
ENDCLASS.
START-OF-SELECTION.
DATA oref TYPE REF TO lcl.
CREATE OBJECT oref.
oref->m( ). " works fine
DATA name TYPE c VALUE 'm'.
CALL METHOD oref->(name). " <-- Runtime Error
In the background all method names are uppercase, so you have to call the method like this:
DATA name TYPE c VALUE 'M'.
On the other hand you can catch this exception, so the program won't dump, even if the method does not exist:
TRY.
CALL METHOD oref->(name).
CATCH cx_sy_dyn_call_illegal_method
INTO DATA(lx_illegal_method).
"handle illegal method call
ENDTRY.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With