Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Syntax Error in CONSTRUCTOR method - but Why?

Former Member
0 Likes
6,424

Hi all

I'm trying to creating a class with a Private Constructor but when I try to activate the class I get the following untranslated error;

Sichtbarkeit des Konstruktors darf nicht spezieller als die

Sichtbarkeit der Instanzerzeugung (CREATE-Zusatz) sein.

Using Google this translates to;

Visibility of the constructor can not be specific as the

Visibility of the production instance (CREATE additional).

I interperate it to mean that I cannot set the visibilty of the Constructor as private. Certainly if I change the visibility to public then the error goes away.

In the book "Next Generation ABAP Development" (by Rich Heilman and Thomas Jung) there are examples that do use Private constructors just like I am trying to do. At present I cannot see what the difference is between my class and the ZCL_CS_COURSE in the book so where have I gone wrong - any ideas?

TIA

Gareth

1 ACCEPTED SOLUTION
Read only

former_member69765
Contributor
2,946

Hi..

Well, Definetely you can make the constructor as Private one.

You are getting the error because : Probably the instantiation type is Public in your properties of class.

In SE24, go to Properties tab and then set the instantiation type as Private. Then declare your constructor as private.

Cheers...

3 REPLIES 3
Read only

former_member69765
Contributor
2,947

Hi..

Well, Definetely you can make the constructor as Private one.

You are getting the error because : Probably the instantiation type is Public in your properties of class.

In SE24, go to Properties tab and then set the instantiation type as Private. Then declare your constructor as private.

Cheers...

Read only

Former Member
0 Likes
2,946

Doh! - I just knew it was going to be something simple that I'd missed.

Thanks

Read only

2,946

Hi,

Constructors can be declared only in the public section due to syntactical reasons. You can restrict the visibility to private at the time of instantiation, by specifying the CREATE PRIVATE addition to the class definition part.

class C1 definition create private.
  public section.
    methods: M1
    , CONSTRUCTOR.
  protected section.
    data ID type I.
endclass.                    "c1 DEFINITION