‎2008 Jul 21 3:18 PM
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
‎2008 Jul 21 3:54 PM
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...
‎2008 Jul 21 3:54 PM
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...
‎2008 Jul 21 3:58 PM
Doh! - I just knew it was going to be something simple that I'd missed.
Thanks
‎2008 Jul 22 5:35 AM
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