Application Development 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: 

constructor

Former Member
0 Kudos

what is static constructor in abap objects?

explain me please?

1 ACCEPTED SOLUTION
4 REPLIES 4

Former Member
0 Kudos

Hi,

static constructor is a method which will be triggered initially.and this will be called automatically.u don't need to create an object and call this.

it will just work like initialization event in the reports.

see this link for more info.

http://help.sap.com/saphelp_nw2004s/helpdata/en/dd/4049c40f4611d3b9380000e8353423/content.htm

http://www.erpgenie.com/abap/OO/eg.htm

rgds,

bharat.

Message was edited by:

Bharat Kalagara

Former Member
0 Kudos

Hi

Static methods, declared as CLASS-METHODS : CLASS_CONSTRUCTOR in the public section of the class definition and are also implemented in the implementation part.

Has no interface parameters and cannot trigger exceptions.

Executed once in each program. It is called automatically for the class before it is accessed for the first time - that is, before one of the following actions:

CREATE OBJECT obj from the class.

Call a static method : [CALL METHOD] class=>meth.

Registering a static event handler method using SET HANDLER class=>meth for obj.

Registering an event handler method for a static event of the class class.

Addressing a static attribute with class=>a.

Exception:-

The static constructor is always called immediately before the action is executed, with one exception:

If the first access to the class is to address a static attribute, the static constructor is executed at the beginning of the processing block (dialog module, event block, procedure) in which the access occurs.

Caution:-

The static constructor must not access its own class. Otherwise a runtime error will occur.

The point at which the static constructor is executed has not yet been finalized, and it may yet be changed. SAP only guarantees that it will be executed before the class is accessed for the first time. It is recommended not to write programs that require the static constructor to be executed at the beginning of a processing block

Reward points for useful Answers

Regards

Anji

Former Member
0 Kudos

hi,

Constructors are special methods that cannot be called using CALL METHOD. Instead, they are called automatically by the system to set the starting state of a new object or class.

There are two types of constructors - <b>instance constructors</b> and <b>static constructors.</b>

<b>The static constructor of a class is the predefined static method CLASS_CONSTRUCTOR.

You declare it in the public section as follows:

CLASS-METHODS CLASS_CONSTRUCTOR</b>

<b>and implement it in the implementation section like any other method.</b>

<b>The static constructor has no parameters.</b>

<b> The system calls the static constructor once for each class, before the class is accessed for the first time.</b>

The static constructor cannot therefore access the components of its own class.

regards,

Ashokreddy.