How To Fix OO272 - Method &1 &2: Method is constructor, but not PUBLIC


SAP Error Message - Details

  • Message type: E = Error

  • Message class: OO - Class Builder/API

  • Message number: 272

  • Message text: Method &1 &2: Method is constructor, but not PUBLIC

  • 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 OO272 - Method &1 &2: Method is constructor, but not PUBLIC ?

    The SAP error message OO272 indicates that there is an issue with the visibility of a constructor method in an ABAP class. Specifically, the error states that the method is a constructor but is not declared as PUBLIC. In ABAP Object-Oriented Programming, constructors are special methods that are called when an instance of a class is created, and they need to be accessible to allow object instantiation.

    Cause:

    The error occurs when:

    • A constructor method is defined in a class but is not declared with the PUBLIC visibility.
    • The constructor is intended to be used outside of the class (e.g., when creating an instance of the class), but its visibility restricts access.

    Solution:

    To resolve this error, you need to change the visibility of the constructor method to PUBLIC. Here’s how you can do that:

    1. Open the Class Definition: Go to the class where the constructor is defined.

    2. Locate the Constructor Method: Find the method that is defined as the constructor (usually named CONSTRUCTOR).

    3. Change the Visibility: Ensure that the constructor is declared under the PUBLIC SECTION of the class definition. It should look something like this:

      CLASS my_class DEFINITION.
        PUBLIC SECTION.
          METHODS: constructor.
        PRIVATE SECTION.
          " Other methods and attributes
      ENDCLASS.
      
      CLASS my_class IMPLEMENTATION.
        METHOD constructor.
          " Constructor implementation
        ENDMETHOD.
      ENDCLASS.
    4. Activate the Changes: After making the changes, activate the class definition.

    Related Information:

    • Constructor Method: In ABAP, the constructor method is a special method that is automatically called when an instance of the class is created. It is used to initialize the object.
    • Visibility Sections: In ABAP classes, there are three visibility sections: PUBLIC, PROTECTED, and PRIVATE. The PUBLIC section allows access from outside the class, while PROTECTED and PRIVATE restrict access.
    • Best Practices: Always ensure that constructors are declared as PUBLIC if you intend to create instances of the class from outside the class itself.

    By following these steps, you should be able to resolve the OO272 error and ensure that your constructor method is accessible for object instantiation.

    • Do you have any question about this error?


      Upgrade now to chat with this error.


Instant HelpGet instant SAP help. Start your 7-day free trial now.


Related SAP Error Messages

Click the links below to see the following related messages:

Click on this link to search all SAP messages.


Rating
The AI Support Assistant is great. It provides comprehensive assistance even on the most difficult issues. I highly recommend this service.
Rate 1
John Jordan
SAP Consultant & Author