Stop googling SAP errors. Use our Free Essentials plan instead - no credit card needed. Start Now

Close

How To Fix WER158 - Method could not be called dynamically


SAP Error Message - Details

  • Message type: E = Error

  • Message class: WER - Messages for the package WER

  • Message number: 158

  • Message text: Method could not be called dynamically

  • Show details Hide details


  • Self-Explanatory Message

    Since SAP believes that this specific error message is 'self-explanatory,' no more information has been given.The majority of messages in the SAP system have a message text, however this is frequently insufficient to comprehend or resolve the problem.

    To make things easier, more detailed information is frequently added to describe the issue, how to fix it, and the necessary steps or configuration modifications.

    Unfortunately, there isn't any extra information in this error notice.



    What else can you do?

    First, use our AnswerBot below to get a possible cause and solution (requires a premium subscription).

    Also, review the in-depth Common Questions & Answers listed below; you could discover a solution there or be able to connect with others who have faced similar challenges.

    You can also try searching the SAP support portal (support.sap.com) but you need a special user ID to access it. It is possible that an SAP support note exists that provides additional details about the mistake or even steps for fixing it.


Smart SAP Assistant

  • What is the cause and solution for SAP error message WER158 - Method could not be called dynamically ?

    The SAP error message WER158: Method could not be called dynamically typically occurs in ABAP Object-Oriented programming when there is an attempt to call a method dynamically (using CALL METHOD or CALL METHOD OF with a method name determined at runtime), but the method call fails.


    Cause

    • Method name is incorrect or does not exist: The method name passed dynamically is either misspelled, does not exist in the class, or is not visible (e.g., private or protected).
    • Object reference is invalid: The object reference on which the method is called is INITIAL or not properly instantiated.
    • Method signature mismatch: The parameters passed dynamically do not match the method's signature.
    • Method is not accessible: The method might be static, but called as an instance method or vice versa.
    • Dynamic call syntax error: The syntax used for dynamic method call is incorrect.

    Solution

    1. Check the method name:

      • Verify that the method name string used in the dynamic call exactly matches the method name defined in the class (case-sensitive).
      • Use cl_abap_typedescr or cl_abap_classdescr to check if the method exists dynamically.
    2. Ensure the object reference is valid:

      • Make sure the object reference is instantiated before the dynamic call.
      • Check for IS BOUND before calling the method dynamically.
    3. Check method visibility and signature:

      • Confirm the method is PUBLIC or accessible in the current context.
      • Verify the parameters passed match the method's signature.
    4. Use correct syntax for dynamic calls:

      • Example of dynamic method call:
        CALL METHOD object_ref (method_name) EXPORTING ... IMPORTING ...
      • Or using CALL METHOD OF:
        CALL METHOD OF object_ref method_name EXPORTING ... IMPORTING ...
    5. Debugging:

      • Set a breakpoint before the dynamic call.
      • Inspect the method name and object reference.
      • Use cl_abap_classdescr=>describe_by_object to get class info and check method existence.

    Related Information

    • SAP Note: Check SAP Notes related to WER158 for specific patches or known issues.
    • ABAP Documentation: Refer to ABAP documentation on dynamic method calls.
    • Class and Method Introspection: Use runtime type services (RTTS) classes like cl_abap_classdescr to inspect classes and methods dynamically.
    • Error Handling: Implement error handling around dynamic calls to catch exceptions like CX_SY_DYNAMIC_CALL_ILLEGAL_METHOD.

    Example

    DATA: obj TYPE REF TO zcl_my_class,
          method_name TYPE string.
    
    obj = NEW zcl_my_class( ).
    method_name = 'MY_METHOD'.
    
    IF obj IS BOUND.
      CALL METHOD obj (method_name).
    ELSE.
      WRITE: 'Object not instantiated'.
    ENDIF.

    If MY_METHOD does not exist or is not public, the error WER158 will occur.


    If you provide the code snippet where the error occurs, I can help you pinpoint the exact issue.

    • Do you have any question about this error?


      Upgrade now to chat with this error.


Instant HelpGet instant SAP help. Sign up for our Free Essentials Plan.


Related SAP Error Messages

Click the links below to see the following related messages:

Click on this link to search all SAP messages.


Rating
ERPlingo's SAP support assistant is amazing. Saves me countless hours trying to solve complex SAP issues myself. It's a real game changer!
Rate 1
Thomas Michael
SAP Consultant, Author & Speaker