Page tree
Skip to end of metadata
Go to start of metadata

When we do the development using the ABAP objects than we need to make sure that we are using the right design patterns.

Design patterns is the patterns which we are using while design and coding of the application.

Singleton design pattern is used when we need to make sure that, application will be able to create only and ONLY one instance of the Class. We can implement the Singleton design patterns in the ABAP by using the CLASS-DATA.

Follow this link


  1. Unknown User (py25qzl)

    In my opinion, this is not the correct implmentation of the singleton pattern. Normally you would like to reuse the instantiation of a singletion in several places by calling the get_instance() method. Therefore you set the visibility of the class to private:


    and create a public class-method get_instance(), which returns the reference to itself:

      METHOD get_instance.

        IF ref IS INITIAL.

          CREATE OBJECT ref.


        returning_param = ref.


    The example in the link only prevents to instantiate the class several times, but if you have a program, which uses several classes, you have to hand over the instance from the first instantiation point to all other classes. With the example above, you could access the instance inside whole program.

     Full example: 

  2. Volker is right. The mentioned webpage shows a worng implementation.

    That code does not even construct a singelton since the instantiation of "lcl_application"  is not private.

    If you invoke

    CREATE OBJECT lo_2nd_apps.

    you will get a new instance. This instance will be different from the class attribute "lo_apps". Thus, the singleton is not a singelton!

  3. Unknown User (vw1f1oc)

    This error was corrected. I think now the page realy show an example of singleton design pattern in ABAP.