Upload
sanjukapoor
View
226
Download
0
Embed Size (px)
Citation preview
8/12/2019 Constructor OOABAP
1/15
8/12/2019 Constructor OOABAP
2/15
What is Constructor
Definition:
Constructor is a one special method which is automatically /
Implicitly called when an object is created.
Purpose/Use:
Constructor are used to initialize current class object.
8/12/2019 Constructor OOABAP
3/15
Rules / Characteristic
Constructor name must be CONSTRUCTOR, or
CLASS_CONSTRUCTOR.
Constructor can be inherited into derived class.
Class Constructor can not be inherited into derived class.
Because every class constructor is made for initialize the its
own attribute of the class but not for initialize another class
attribute.
8/12/2019 Constructor OOABAP
4/15
Types of Constructor
Constructor (Instance Constructor)
Class Constructor ( Static Constructor)
8/12/2019 Constructor OOABAP
5/15
Instance Constructor
To create a Instance Constructor use Constructor keyword.
Instance constructor is executed automatically for every object
creation.
Instance constructor is by default is private.
We will not provide Explicit any return type to constructor.
8/12/2019 Constructor OOABAP
6/15
Static Constructor
To design static Constructor use CLASS_CONSTRUCTOR.
Static constructor is executed automatically for either
i. When class name is used. (Only Once)
ii. When first object is created. (Only Once)
Note:
Static Constructor is triggered in the above 2 scenario but which one scenariocomes first.
Class Constructor is by default is public.
We will not provide any parameter to Class-Constructor.
We can not inherit Class Constructor.
8/12/2019 Constructor OOABAP
7/15
Constructor
Method
Methods are executedexplicitly by developer.
Methods can haveimporting, exporting,changing, returningparameters.
Constructor
Constructors are executedimplicitly.
We can not provide explicitlyreturning parameters toinstance constructor butStatic constructor cant haveany parameters.
8/12/2019 Constructor OOABAP
8/15
Advantage
I) Constructor eliminate in a placing value.
0
0
X X X
10
20
X X X
Object Object
ConstructorMethod
Class Class
8/12/2019 Constructor OOABAP
9/15
II) Constructor eliminate calling of Ordinary Method.
Ordinary Method:
All Method which are not similar to CONSTRUCTOR
name is know as Ordinary Method.
Special Method:
All Method which are similar to CONSTRUCTOR name is
known as Special Method.
8/12/2019 Constructor OOABAP
10/15
Overloaded Constructor
*** ABAP Does not support Overloaded Constructor
Over Load= Class name is Same + Signature is Different
Signature:
No of Parameter
Type of Parameter
Order of Parameter
At Least one will be
Different
8/12/2019 Constructor OOABAP
11/15
Visibility Chart
Private Protected Public
Private Y Y Y
Protected N Y Y
Public N N Y
8/12/2019 Constructor OOABAP
12/15
Method Parameters
Importing
Provide the input value in report program.
We can use more then importing parameters.
Exporting
Provide the output value in report program.
It will return value when program is executed completely.We can pass table throw exporting parameters.
We can use more then exporting parameters.
8/12/2019 Constructor OOABAP
13/15
Method Parameters
Changing
It treated as a importing as well as exporting parameters.
We can use more then changing parameters.
Returning
It will return the value in the mid of program execution.
We can not pass table throw returning parameters. If we are using returning parameters we cant use exporting
and changing parameters.
We cant use more then one returning parameters.
8/12/2019 Constructor OOABAP
14/15
Function Module versus Method
Function Module
Returning parameter is notthere.
Method
Returning parameters isthere.
8/12/2019 Constructor OOABAP
15/15