Static and instance constructor in ABAP Objects
Page 1 of 1
Static and instance constructor in ABAP Objects
As we know c onstructors 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 - instance constructors and static
constructors. Constructors are methods with a predefined name. To use them, you must
declare them explicitly in the class.
The instance constructor of a class is the predefined instance method CONSTRUCTOR. You
declare it in the public section as follows:
METHODS CONSTRUCTOR
IMPORTING.. [VALUE(]<ii>[)] TYPE type [OPTIONAL]..
EXCEPTIONS.. <ei>.
and implement it in the implementation section like any other method. The system calls the
instance constructor once for each instance of the class, directly after the object has been
created in the CREATE OBJECT statement. You can pass the input parameters of the
instance constructor and handle its exceptions using the EXPORTING and EXCEPTIONS
additions in the CREATE OBJECT statement.
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.
and implement it in the implementation section like any other method. The static constructor
has no parameters. The system calls the static constructor once for each class, before the
class is accessed for the first time. The static constructor cannot therefore access the
components of its own class.
Uma_ABAP- Posts : 56
Join date : 2012-03-31
Similar topics
» Static and instance components in ABAP Objects
» Constructor methods ABAP Objects
» Constructor and inheritance in ABAP Objects with example
» declaring static and instance components in ABAP Objects
» Parameterized constructor in ABAP
» Constructor methods ABAP Objects
» Constructor and inheritance in ABAP Objects with example
» declaring static and instance components in ABAP Objects
» Parameterized constructor in ABAP
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum
Mon Aug 20, 2012 4:37 pm by Admin
» Difference between Type and Like
Thu Jun 07, 2012 2:40 pm by Admin
» How to handle table control fields in Module Pool program?
Wed May 09, 2012 2:41 am by govind
» Three tables inner join in SAP
Thu May 03, 2012 4:47 pm by Uma_ABAP
» Creating table type in ABAP
Sat Apr 28, 2012 9:03 pm by Uma_ABAP
» Creating user defined types and structures in ABAP
Sat Apr 28, 2012 8:55 pm by Uma_ABAP
» Creating Dynamic Internal Table and Dynamic Field catalog in SAP-ABAP
Fri Apr 27, 2012 11:00 am by Admin
» Copy Custom PF-Status from Standard program to Custom Program in ALV
Thu Apr 26, 2012 9:52 pm by Uma_ABAP
» Calculate/find number of working days between two dates in SAP
Tue Apr 24, 2012 2:06 pm by Uma_ABAP