Do you have any question about this error?
Message type: E = Error
Message class: OO - Class Builder/API
Message number: 118
Message text: Methods cannot be both abstract and final
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.
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.
OO118
- Methods cannot be both abstract and final ?The SAP error message OO118, which states "Methods cannot be both abstract and final," typically occurs in ABAP Object-Oriented programming when there is a conflict in the method definition of a class. Specifically, it indicates that a method is being declared as both
ABSTRACT
andFINAL
, which is not allowed in ABAP.Cause:
- Abstract Method: An abstract method is a method that is declared without an implementation. It must be implemented in any subclass that inherits from the class containing the abstract method.
- Final Method: A final method is a method that cannot be overridden in any subclass. It has a complete implementation and is intended to be used as is.
Since an abstract method is meant to be overridden and a final method is not, declaring a method as both creates a logical contradiction, leading to this error.
Solution:
To resolve this error, you need to modify the method declaration in your class. You should choose either to declare the method as
ABSTRACT
or asFINAL
, but not both. Here are the steps to fix the issue:
- Identify the Method: Locate the method in your class that is causing the error.
- Decide on the Method Type:
- If you want the method to be implemented in subclasses, remove the
FINAL
keyword and keep it asABSTRACT
.- If you want the method to have a fixed implementation that cannot be changed in subclasses, remove the
ABSTRACT
keyword and keep it asFINAL
.- Update the Method Declaration: Modify the method declaration accordingly.
Example:
Here’s an example of how to correct the method declaration:
Incorrect Declaration:
CLASS my_class DEFINITION. PUBLIC SECTION. METHODS my_method ABSTRACT FINAL. ENDCLASS.
Correct Declaration (as Abstract):
CLASS my_class DEFINITION. PUBLIC SECTION. METHODS my_method ABSTRACT. ENDCLASS.
Correct Declaration (as Final):
CLASS my_class DEFINITION. PUBLIC SECTION. METHODS my_method FINAL. ENDCLASS.
Related Information:
ABSTRACT
for methods that require implementation in subclasses and FINAL
for methods that should remain unchanged.By following these guidelines, you should be able to resolve the OO118 error and ensure your ABAP classes are correctly defined.
Get instant SAP help. Start your 7-day free trial now.
OO117
Type & cannot be referenced using LIKE
Self-Explanatory Message Since SAP believes that this specific error message is 'self-explanatory,' no more information has been given.The majority of...
OO116
For event-handling methods the event must be fully specified.
Self-Explanatory Message Since SAP believes that this specific error message is 'self-explanatory,' no more information has been given.The majority of...
OO119
Protected methods should not be final
Self-Explanatory Message Since SAP believes that this specific error message is 'self-explanatory,' no more information has been given.The majority of...
OO120
A private method cannot be final (they are not inherited by subclasses)
Self-Explanatory Message Since SAP believes that this specific error message is 'self-explanatory,' no more information has been given.The majority of...
Click on this link to search all SAP messages.