OOPS in ABAP OOPS in ABAP O OOOPPSSiinnAABBAAPP 1111
Object
Object
Object-
Object-
-Oriented
-Oriented
Oriented
Oriented
Programming in
Programming in
Programming in
Programming in
ABAP
ABAP
ABAP
ABAP
Presented by
Presented by
Presented by
Presented by
Pooja Nayak
Pooja Nayak
Pooja Nayak
Pooja Nayak
OOPS in ABAP OOPS in ABAP O OOOPPSSiinnAABBAAPP 2222
SESSION OVERVIEW
SESSION OVERVIEW
SESSION OVERVIEW
SESSION OVERVIEW
What is Object Orientation?What is Object Orientation?What is Object Orientation?What is Object Orientation?
AttriAttriAttriAttributes of butes of butes of butes of Object Oriented ProgrammingObject Oriented ProgrammingObject Oriented ProgrammingObject Oriented Programming
ABAP ObjectsABAP ObjectsABAP ObjectsABAP Objects
How to implement classes,events...How to implement classes,events...How to implement classes,events...How to implement classes,events...
Advantages of OOP in Advantages of OOP in Advantages of OOP in Advantages of OOP in ABAABAABAABAPPPP
SAP Business ObjectsSAP Business ObjectsSAP Business ObjectsSAP Business Objects
OOPS in ABAP OOPS in ABAP O
OOOPPSSiinnAABBAAPP 3333
What is Object
What is Object
Orientatio
Orientatio
n?
n?
What is Object
What is Object
Orientatio
Orientatio
n?
n?
Type of problemType of problemType of problem-Type of problem--solving method in which the software-solving method in which the softwaresolving method in which the ssolving method in which the softwareoftware solution reflects real
solution reflects real solution reflects
real-solution reflects real--world objects.-world objects.world objects.world objects.
Emphasis is given to data rather than to Emphasis is given to data rather than to Emphasis is given to data rather than to Emphasis is given to data rather than to proceduresproceduresproceduresprocedures
Data is hidden and cannot be accessed by externalData is hidden and cannot be accessed by externalData is hidden and cannot be accessed by externalData is hidden and cannot be accessed by external functions.
functions. functions. functions.
Merits Of Object
Merits Of Object OrientationOrientation Merits Of Object
Merits Of Object OrientationOrientation
Complex software systems become easier toComplex software systems become easier toComplex software systems become easier toComplex software systems become easier to understand. understand. understand. understand.
OO systems are easier to scale by using OO systems are easier to scale by using OO systems are easier to scale by using OO systems are easier to scale by using the concept of the concept of the concept of the concept of reusability.
reusability. reusability. reusability.
OOPS in ABAP OOPS in ABAP O OOOPPSSiinnAABBAAPP 4444 Classes Classes Data Encapsulation Data Encapsulation Inheritance Inheritance Polymorphism Polymorphism
Attributes of Object
Attributes of Object
Oriented
Oriented
Attributes of Object
Attributes of Object
Oriented
Oriented
Programming
Programming
Programming
Programming
Objects ObjectsOOPS in ABAP OOPS in ABAP O OOOPPSSiinnAABBAAPP 5555
OBJECTS
OBJECTS
OBJECTS
OBJECTS
Is any realIs any realIs any real-Is any real--time entity (eg. Employee, customer etc )-time entity (eg. Employee, customer etc )time entity (eg. Employee, customer etc )time entity (eg. Employee, customer etc )
Contains data and behaviour.Contains data and behaviour.Contains data and behaviour.Contains data and behaviour.
Operations are done through Operations are done through Operations are done through Operations are done through message passing.message passing.message passing.message passing.
Format of message isFormat of message isFormat of message isFormat of message is
message:[destination,operation,parameters] message:[destination,operation,parameters] message:[destination,operation,parameters] message:[destination,operation,parameters]
destination
destination receiver receiver object object stimulated stimulated by by messagemessage destination
destination receiver receiver object object stimulated stimulated by by messagemessage operation
operation method method that that is is to to receive receive the the messagemessage operation
operation method method that that is is to to receive receive the the messagemessage parameters
parameters informatioinformation n needed needed for for operation operation to to bebe parameters
parameters informatioinformation n needed needed for for operation operation to to bebe successful.
successful. successful. successful.
OOPS in ABAP OOPS in ABAP O OOOPPSSiinnAABBAAPP 6666
CLASS
CLASS
CLASS
CLASS
Central element of object orientation.Central element of object orientation.Central element of object orientation.Central element of object orientation.
Abstract description of an object. Abstract description of an object. Abstract description of an object. Abstract description of an object.
Defines state and behaviour of objects.Defines state and behaviour of objects.Defines state and behaviour of objects.Defines state and behaviour of objects.
Structure of Class Structure of Class Structure of Class Structure of Class
Classes contain Classes contain Classes contain Classes contain componentcomponentcomponentcomponents.s.s.s.
Each component is assigned a visibility section.Each component is assigned a visibility section.Each component is assigned a visibility section.Each component is assigned a visibility section.
OOPS in ABAP OOPS in ABAP O
OOOPPSSiinnAABBAAPP 7777
Data
Data
Encapsulatio
Encapsulatio
n
n
Data
Data
Encapsulatio
Encapsulatio
n
n
Protective covering preventing data and code fromProtective covering preventing data and code fromProtective covering preventing data and code fromProtective covering preventing data and code from being defined outside the covering.
being defined outside the covering. being defined outside the covering. being defined outside the covering.
Each obj. has an interface, which determines howEach obj. has an interface, which determines howEach obj. has an interface, which determines howEach obj. has an interface, which determines how other obj. can interact with it.
other obj. can interact with it. other obj. can interact with it. other obj. can interact with it.
Objs restrict visibility of their resources to other users.Objs restrict visibility of their resources to other users.Objs restrict visibility of their resources to other users.Objs restrict visibility of their resources to other users.
Three visibility mechanisms.Three visibility mechanisms.Three visibility mechanisms.Three visibility mechanisms.
Private sectionPrivate sectionPrivate sectionPrivate section
Public sectionPublic sectionPublic sectionPublic section
Protected sectionProtected sectionProtected sectionProtected section
All component All component All component All components s s s defined in public section are defined in public section are defined in public section are defined in public section are accessibleaccessibleaccessibleaccessible to all users of the c
to all users of the class, methods of the class and anylass, methods of the class and any to all users of the c
to all users of the class, methods of the class and anylass, methods of the class and any inherited classes.
inherited classes. inherited classes. inherited classes.
OOPS in ABAP OOPS in ABAP O
OOOPPSSiinnAABBAAPP 8888
Data Encapsulation contd..
Data Encapsulation contd..
Data Encapsulation contd..
Data Encapsulation contd..
All component All component All component All components s s s declared in private section are declared in private section are declared in private section are declared in private section are onlyonlyonlyonly visible in the methods of same class.
visible in the methods of same class. visible in the methods of same class. visible in the methods of same class.
All components declared in protected section are All components declared in protected section are All components declared in protected section are All components declared in protected section are visiblevisiblevisiblevisible to method
to methods s of the class and those cof the class and those classes that inheritlasses that inherit to method
to methods s of the class and those cof the class and those classes that inheritlasses that inherit from this class.
from this class. from this class. from this class.
Interfaces completely describes how the user of Interfaces completely describes how the user of Interfaces completely describes how the user of Interfaces completely describes how the user of thethethethe class interacts with it.
class interacts with it. class interacts with it. class interacts with it.
Attributes will be hidden and user will use methods of Attributes will be hidden and user will use methods of Attributes will be hidden and user will use methods of Attributes will be hidden and user will use methods of class to manipula
class to manipulate te the data.the data. class to manipula
OOPS in ABAP OOPS in ABAP O OOOPPSSiinnAABBAAPP 9999
INHERITANCE
INHERITANCE
INHERITANCE
INHERITANCE
RelationshiRelationshiRelationshiRelationship in p in p in p in which a class (subclass) inheritswhich a class (subclass) inheritswhich a class (subclass) inheritswhich a class (subclass) inherits the main features of another
the main features of another class (superclass).class (superclass). the main features of another
the main features of another class (superclass).class (superclass).
Subclass can add new Subclass can add new Subclass can add new Subclass can add new components (attributes, methods,components (attributes, methods,components (attributes, methods,components (attributes, methods, events)
events) and reand replace inhplace inherited methoerited methods with ds with its its ownown events)
events) and reand replace inhplace inherited methoerited methods with ds with its its ownown implementation. implementation. implementation. implementation.
Types of InheritanceTypes of InheritanceTypes of InheritanceTypes of Inheritance
1) 1) 1)
1) Single level InheritanceSingle level InheritanceSingle level InheritanceSingle level Inheritance 2)
2) 2)
2) MultipleMultipleMultipleMultiple 3)
3) 3)
3) HierarchicalHierarchicalHierarchicalHierarchical 4)
4) 4)
OOPS in ABAP OOPS in ABAP O OOOPPSSiinnABABAAPP 10101100
POLYMORPHISM
POLYMORPHISM
POLYMORPHISM
POLYMORPHISM
Comes from the Greek word ³many forms´.Comes from the Greek word ³many forms´.Comes from the Greek word ³many forms´.Comes from the Greek word ³many forms´.
Allows one interface to be used for a general class of Allows one interface to be used for a general class of Allows one interface to be used for a general class of Allows one interface to be used for a general class of actions. actions. actions. actions.
When objects from different classes react differently toWhen objects from different classes react differently toWhen objects from different classes react differently toWhen objects from different classes react differently to the same procedural call.
the same procedural call. the same procedural call. the same procedural call.
User can work with different classes User can work with different classes User can work with different classes User can work with different classes in a similar way,in a similar way,in a similar way,in a similar way, regardless of their
regardless of their implemeimplementation.ntation. regardless of their
regardless of their implemeimplementation.ntation.
Allows improved code organization and readability as Allows improved code organization and readability as Allows improved code organization and readability as Allows improved code organization and readability as well
well as as creation creation of of ³extensible´ programs.³extensible´ programs. well
OOPS in ABAP OOPS in ABAP O OOOPPSSiinnABABAAPP 11111111
ABAP Objects
ABAP Objects
ABAP Objects
ABAP Objects
Complete set of ObjectComplete set of ObjectComplete set of Object-Complete set of Object--Oriented statements introduced-Oriented statements introducedOriented statements introducedOriented statements introduced
in
in conventional conventional ABAP.ABAP.
in
in conventional conventional ABAP.ABAP.
ABAP Objects was introduced with SAP Basis Release ABAP Objects was introduced with SAP Basis Release ABAP Objects was introduced with SAP Basis Release ABAP Objects was introduced with SAP Basis Release
4.5 4.5 4.5 4.5
Classes, Interfaces, EventsClasses, Interfaces, EventsClasses, Interfaces, EventsClasses, Interfaces, Events
ABAP Objects was completed with SAP Basis Release ABAP Objects was completed with SAP Basis Release ABAP Objects was completed with SAP Basis Release ABAP Objects was completed with SAP Basis Release
4.6 4.6 4.6 4.6
Inheritance, Dynamic InvokeInheritance, Dynamic InvokeInheritance, Dynamic InvokeInheritance, Dynamic Invoke
Some enhancements were added with SAP WSome enhancements were added with SAP Web Applicationeb Application
Server, Releases 6.10, 6.20.
Server, Releases 6.10, 6.20.
OOPS in ABAP OOPS in ABAP O
OOOPPSSiinnABABAAPP 12121122
ABAP Objects contd..
ABAP Objects contd..
ABAP Objects contd..
ABAP Objects contd..
Runtime environment Runtime environment Runtime environment Runtime environment
ABAP Workbench allows you to create R/3 Repository ABAP Workbench allows you to create R/3 Repository ABAP Workbench allows you to create R/3 Repository ABAP Workbench allows you to create R/3 Repository Objects like programs, lock objects and so on.
Objects like programs, lock objects and so on. Objects like programs, lock objects and so on. Objects like programs, lock objects and so on.
Using Function Modules, we can encapsulate functionsUsing Function Modules, we can encapsulate functionsUsing Function Modules, we can encapsulate functionsUsing Function Modules, we can encapsulate functions in different programs with defined interfaces.
in different programs with defined interfaces. in different programs with defined interfaces. in different programs with defined interfaces.
Object Oriented enhancement of ABAP is based Object Oriented enhancement of ABAP is based Object Oriented enhancement of ABAP is based Object Oriented enhancement of ABAP is based onononon models of Java and C++.
models of Java and C++. models of Java and C++. models of Java and C++. Object References Object References Object References Object References
Used to access objects from ABAP program Used to access objects from ABAP program Used to access objects from ABAP program Used to access objects from ABAP program andandandand contained in
contained in contained in
OOPS in ABAP OOPS in ABAP O
OOOPPSSiinnABABAAPP 13131133
ABAP Objects contd«
ABAP Objects contd«
ABAP Objects contd«
ABAP Objects contd«
Two types of referencesTwo types of referencesTwo Two types types of of references references ---- Class ReferencesClass ReferencesCCllaasss s RReeffeerreenncceess
Interface References. Interface References. Interface References. Interface References.
Class References are defined using the Class References are defined using the Class References are defined using the Class References are defined using the additionadditionadditionaddition
<cref> TYPE REF TO <class>
<cref> TYPE REF TO <class>
<cref> TYPE REF TO <class>
<cref> TYPE REF TO <class>
in the TYPES or DATA statement.
in the TYPES or DATA statement.
in the TYPES or DATA statement.
in the TYPES or DATA statement.
It allows the user to create an It allows the user to create an It allows the user to create an It allows the user to create an instance of theinstance of theinstance of theinstance of the
class. class. class. class.
Interface References are defined using theInterface References are defined using theInterface References are defined using theInterface References are defined using the
addition
addition
addition
addition
«
« TYPE REF TO <intf>TYPE REF TO <intf>
«
« TYPE REF TO <intf>TYPE REF TO <intf>
in the TYPES or DATA statement.
in the TYPES or DATA statement.
in the TYPES or DATA statement.
in the TYPES or DATA statement.
<<<<intf> should be declared before intf> should be declared before intf> should be declared before intf> should be declared before actual reference declarationactual reference declarationactual reference declarationactual reference declaration
occurs.
occurs.
occurs.
OOPS in ABAP OOPS in ABAP O
OOOPPSSiinnABABAAPP 14141144
ABAP Objects contd«
ABAP Objects contd«
ABAP Objects contd«
ABAP Objects contd«
After creating a reference variable for a After creating a reference variable for a After creating a reference variable for a After creating a reference variable for a class, you canclass, you canclass, you canclass, you can create an object using the statement
create an object using the statement create an object using the statement create an object using the statement
CREATE CREATE CRE
CREATATE E OBJECTOBOBOBJECTJEJECTCT <cref>.<cref>.<cref>.<cref>.
This creates an instance of the object This creates an instance of the object This creates an instance of the object This creates an instance of the object andandandand <<<<cref>cref>cref>cref>
contains the reference to the object. contains the reference to the object. contains the reference to the object. contains the reference to the object. Addressing the components of
Addressing the components of objectsobjects Addressing the components of
Addressing the components of objectsobjects Instance c
Instance componenomponentsts Instance c
Instance componenomponentsts
To access attributesTo access attributesTo access attributesTo access attributes <<<<attr>:attr>:attr>:attr>: <c <c <c <cref> -ref> ref> -ref> -> -> > > < < < <attr> attr> attr> attr>
To access methodsTo access methodsTo access methodsTo access methods <<<<meth>:meth>:meth>:meth>: CALLCALLCACALL LL METHOD METHODMETMETHOHODD <cref><cref><cref>-<cref>-->->>> <meth>
<meth>
<meth>
OOPS in ABAP OOPS in ABAP O OOOPPSSiinnABABAAPP 15151155 Static components Static components Static components Static components
To access attributesTo access attributesTo access attributesTo access attributes <<<<attr>:attr>:attr>:attr>: <<<<class> =>class> =>class> =>class> => <<<<attr>.attr>.attr>.attr>.
To access methodsTo access methodsTo access methodsTo access methods <<<<meth>:meth>:meth>:meth>: CCCCAAALLALLLLLL METHODMETHODMEMETHTHODOD <<<<class>class>class>class> => => <<meth>meth> => => <<meth>meth>
Within a class, you can access individual Within a class, you can access individual Within a class, you can access individual Within a class, you can access individual componencomponencomponencomponentstststs using the keyword ME.
using the keyword ME. using the keyword ME. using the keyword ME.
For example: MEFor example: ME -For example: ME -For example: ME ->->>> <<<<attr>attr>attr>attr>
C
CALLALL
C
OOPS in ABAP OOPS in ABAP O OOOPPSSiinnABABAAPP 16161166
Classes in ABAP
Classes in ABAP
Classes in ABAP
Classes in ABAP
Types of Classes Types of Classes Types of Classes Types of Classes Local Classes Local Classes Local Classes Local Classes Defined within ABAP program.Defined within ABAP program.Defined within ABAP program.Defined within ABAP program.
Can be used only with that program.Can be used only with that program.Can be used only with that program.Can be used only with that program.
Global Classes Global Classes Global Classes Global Classes
Defined in class builder SE24.Defined in class builder SE24.Defined in class builder SE24.Defined in class builder SE24.
Stored centrally in class library in R/3 repository.Stored centrally in class library in R/3 repository.Stored centrally in class library in R/3 repository.Stored centrally in class library in R/3 repository.
Can be accessed from all programs in R/3 Can be accessed from all programs in R/3 Can be accessed from all programs in R/3 Can be accessed from all programs in R/3 system.system.system.system.
For eg.For eg.For eg.For eg. CL_GUI_ALV_GCL_GUI_ALV_GRRID,ID,
CL_GUI_CUS
OOPS in ABAP OOPS in ABAP O
OOOPPSSiinnABABAAPP 17171177
Defining local classes in ABAP
Defining local classes in ABAP
Defining local classes in ABAP
Defining local classes in ABAP
The The The The main main main main components components components components are are are are AttributesAttributesAttributesAttributes, , , , Methods Methods Methods Methods andandandand Events. Events. Events. Events.
In ABAP, classes are defined between CLASS andIn ABAP, classes are defined between CLASS andIn ABAP, classes are defined between CLASS andIn ABAP, classes are defined between CLASS and ENDCLASS statements. ENDCLASS statements. ENDCLASS statements. ENDCLASS statements.
Class definitiClass definitiClass definitiClass definition on on on consists of declaration andconsists of declaration andconsists of declaration andconsists of declaration and implementation parts. implementation parts. implementation parts. implementation parts.
Syntax for class definition isSyntax for class definition isSyntax for class definition isSyntax for class definition is CLASS
CLASS CLASS
CLASS classnameclassnameclassnameclassname DEFINITIONDEFINITIONDEFINITIONDEFINITION....
PUBLIC PUBLIC PUB
PUBLIC LIC SECSECSECTIONSECTIONTIOTIONN....
*declare public variables and methods.
*declare public variables and methods.
*declare public variables and methods.
*declare public variables and methods.
PRIVATE PRIVATE PRI
PRIVATVATE E SECTIONSECSECSECTIONTIOTIONN....
*declare private data.
*declare private data.
*declare private data.
*declare private data.
ENDCLASS ENDCLASS ENDCLASS ENDCLASS....
OOPS in ABAP OOPS in ABAP O
OOOPPSSiinnABABAAPP 18181188
Understandin
Understandin
g
g
Classes contd..
Classes contd..
Understandin
Understandin
g
g
Classes contd..
Classes contd..
The syntax for class implementation isThe syntax for class implementation isThe syntax for class implementation isThe syntax for class implementation is
CLASS
CLASS class_name class_name IMPLEMENTATIMPLEMENTATION.ION. CLASS
CLASS class_name class_name IMPLEMENTATIMPLEMENTATION.ION. METHOD CONSTRUCTOR.
METHOD CONSTRUCTOR. METHOD CONSTRUCTOR. METHOD CONSTRUCTOR. *initialisin
*initialising g the variablesthe variables *initialisin
*initialising g the variablesthe variables ENDMETHOD. ENDMETHOD. ENDMETHOD. ENDMETHOD. METHOD method_name. METHOD method_name. METHOD method_name. METHOD method_name.
*write code for the defined methods *write code for the defined methods *write code for the defined methods *write code for the defined methods ENDMETHOD. ENDMETHOD. ENDMETHOD. ENDMETHOD. ENDCLASS. ENDCLASS. ENDCLASS. ENDCLASS.
OOPS in ABAP OOPS in ABAP O
OOOPPSSiinnABABAAPP 19191199
Understanding Class Components
Understanding Class Components
Understanding Class Components
Understanding Class Components
Attributes Attributes Attributes Attributes
They are internal data variables in a class and can takeThey are internal data variables in a class and can takeThey are internal data variables in a class and can takeThey are internal data variables in a class and can take any ABAP data type.
any ABAP data type. any ABAP data type. any ABAP data type.
Can be classified intoCan be classified intoCan be classified into instanceCan be classified into instanceininstastancence attattatattrtrribribibibuteuteututesesss ananand staticand staticdd staticstatic attributes attributes attributes. attributes...
InstanceInstanceInsInstantancece attrattrattattribribibutibututeuteesesss are declared using DATA keywordare decare decare declared using DATA keywordlarelared using DATA ked using DATA keywywordord and determine the state of the instance.
and determine the state of the instance. and determine the state of the instance. and determine the state of the instance.
Must create an object before working with instanceMust create an object before working with instanceMust create an object before working with instanceMust create an object before working with instance attributes. attributes. attributes. attributes.
StaticStaStaStatictictic attratatattrtritriibutibutbutbuteseseses are declared using CLASS-are dare dare declared using CLASS-eclaeclared usinred using CLASg CLASSS-DATA-DATADATADATA keyword and determine the state of the class.
keyword and determine the state of the class. keyword and determine the state of the class. keyword and determine the state of the class.
Need not create an object before working with staticNeed not create an object before working with staticNeed not create an object before working with staticNeed not create an object before working with static attributes.
attributes. attributes. attributes.
OOPS in ABAP OOPS in ABAP O OOOPPSSiinnABABAAPP 20202200 Methods Methods Methods( Procedures) Methods( Procedures)( Procedures)( Procedures)
They can access all class attributes and They can access all class attributes and They can access all class attributes and They can access all class attributes and have parameter have parameter have parameter have parameter interface similar to the Function Modules (IMPORTING, interface similar to the Function Modules (IMPORTING, interface similar to the Function Modules (IMPORTING, interface similar to the Function Modules (IMPORTING, EXPORTING, CHANGING). EXPORTING, CHANGING). EXPORTING, CHANGING). EXPORTING, CHANGING).
Like Attributes, there are instance methods and staticLike Attributes, there are instance methods and staticLike Attributes, there are instance methods and staticLike Attributes, there are instance methods and static methods. methods. methods. methods.
Instance methodInstance methodInstance methodInstance methods are s are s are s are declared using METHODSdeclared using METHODSdeclared using METHODSdeclared using METHODS keywor
keyword and d and can access all the attributes of can access all the attributes of the class.the class. keywor
keyword and d and can access all the attributes of can access all the attributes of the class.the class.
Static methoStatic methoStatic methoStatic methods ds ds ds are declared using CLASSare declared using CLASSare declared using CLASS-are declared using CLASS--METHODS-METHODSMETHODSMETHODS keyword and can access only static attributes of the keyword and can access only static attributes of the keyword and can access only static attributes of the keyword and can access only static attributes of the class.
class. class. class.
OOPS in ABAP OOPS in ABAP O OOOPPSSiinnABABAAPP 21212211
The syntax of using methods isThe syntax of using methods isThe syntax of using methods isThe syntax of using methods is
METHO
METHODSDS <met><met>
METHO
METHODSDS <met><met>
I
IMPORTMPORTIINNGG : [: [VALUVALUE(] <iE(] <i I
IMPORTMPORTIINNGG : [: [VALUVALUE(] <iE(] <iiiii> [)]TYPE type]> [)]TYPE type]> [)]TYPE type]> [)]TYPE type]
[OPT
[OPTIIONONALAL] EXPORT] EXPORTIINNGG : [: [VALUVALUE(] <eE(] <e
[OPT
[OPTIIONONALAL] EXPORT] EXPORTIINNGG : [: [VALUVALUE(] <eE(] <eiiii> [)] TYPE> [)] TYPE> [)] TYPE> [)] TYPE
type]
type]
type]
type]
[OPT
[OPTIIONONALAL]] CCHHAANNGIGINNGG : [: [VALUVALUE(] <cE(] <c
[OPT
[OPTIIONONALAL]] CCHHAANNGIGINNGG : [: [VALUVALUE(] <cE(] <ciiii> [)] TYPE> [)] TYPE> [)] TYPE> [)] TYPE
type]
type]
type]
type]
[OPT
[OPTIIONONALAL] RET] RETUURNRNIINNGG VALUVALUE(<rE(<r
[OPT
[OPTIIONONALAL] RET] RETUURNRNIINNGG VALUVALUE(<rE(<r1111>)>)>)>)
EX
EXCCEPTEPTIIONONSS: : <e<e
EX
EXCCEPTEPTIIONONSS: : <e<eiiii>>>>....
The additions like IMPORTING, EXPORTING etc defineThe additions like IMPORTING, EXPORTING etc defineThe additions like IMPORTING, EXPORTING etc defineThe additions like IMPORTING, EXPORTING etc define attributes of interface parameters like pass
attributes of interface parameters like pass attributes of interface parameters like
pass-attributes of interface parameters like pass--by-byby-by--value-valuevaluevalue (VALUE), its type (TYPE) and if it is optional (like
(VALUE), its type (TYPE) and if it is optional (like (VALUE), its type (TYPE) and if it is optional (like (VALUE), its type (TYPE) and if it is optional (like OPTIONAL).
OPTIONAL). OPTIONAL). OPTIONAL).
OOPS in ABAP OOPS in ABAP O OOOPPSSiinnABABAAPP 22222222 Implementing methods Implementing methods Implementing methods Implementing methods
The syntax for implemThe syntax for implemThe syntax for implemThe syntax for implementation of a method isentation of a method isentation of a method isentation of a method is
METHOD
METHOD
METHOD
METHOD methodname.methodname.methodname.methodname.
*enter the code here
*enter the code here
*enter the code here
*enter the code here
ENDMETHOD ENDMETHOD ENDMETHOD ENDMETHOD....
The interface parameters needn¶t be specified in implemThe interface parameters needn¶t be specified in implemThe interface parameters needn¶t be specified in implemThe interface parameters needn¶t be specified in implementation.entation.entation.entation.
To handle error situations, statements like RAISETo handle error situations, statements like RAISETo handle error situations, statements like RAISETo handle error situations, statements like RAISE <<<<exception> ,exception> ,exception> ,exception> ,
MESSAGE RAISING etc can be used.
MESSAGE RAISING etc can be used.
MESSAGE RAISING etc can be used.
MESSAGE RAISING etc can be used.
Calling Methods Calling Methods Calling Methods Calling Methods
The way of addressing a method depends on the method itself andThe way of addressing a method depends on the method itself andThe way of addressing a method depends on the method itself andThe way of addressing a method depends on the method itself and from where you are calling it.
from where you are calling it.
from where you are calling it.
from where you are calling it.
The basic form of calling a method isThe basic form of calling a method isThe basic form of calling a method isThe basic form of calling a method is
CALL METHOD methodname.
CALL METHOD methodname.
CALL METHOD methodname.
OOPS in ABAP OOPS in ABAP O OOOPPSSiinnABABAAPP 23232233
Class Definition
Class Definition
Class Definition
-Class Definition -
-> An Example
-> An Example
> An Example
> An Example
CLASS
CLASS CL_EMPLOYEECL_EMPLOYEE DEFINITION.DEFINITION.
CLASS
CLASS CL_EMPLOYEECL_EMPLOYEE DEFINITION.DEFINITION.
PUBLIC
PUBLIC SECTION.SECTION.
PUBLIC
PUBLIC SECTION.SECTION. TYPE
TYPESS::
TYPE
TYPESS::
BE
BEGIGIN OF TN OF T__EMPEMPLLOYEEOYEE,,
BE
BEGIGIN OF TN OF T__EMPEMPLLOYEEOYEE,,
NO TYPE NO TYPE I,I, NO TYPE NO TYPE I,I, N NAAME TYPEME TYPE SSTRTRIINNG,G, N NAAME TYPEME TYPE SSTRTRIINNG,G, EN
ENDD OF TOF T__EMPEMPLLOYEE.OYEE.
EN
ENDD OF TOF T__EMPEMPLLOYEE.OYEE.
METHODS METHODS:: METHODS METHODS:: CONSTRUCTOR CONSTRUCTOR CONSTRUCTOR CONSTRUCTOR IMPORTING IMPORTING:: IMPORTING IMPORTING:: I
IMM__EMPEMPLLOYEEOYEE__NO TYPENO TYPE II
I
IMM__EMPEMPLLOYEEOYEE__NO TYPENO TYPE II
I
IMM__EMPEMPLLOYEEOYEE__NNAAME TYPEME TYPE SSTRTRIINNG,G,
I
IMM__EMPEMPLLOYEEOYEE__NNAAME TYPEME TYPE SSTRTRIINNG,G,
DISPLAY_EMPLOYEE.
DISPLAY_EMPLOYEE.
DISPLAY_EMPLOYEE.
OOPS in ABAP OOPS in ABAP O OOOPPSSiinnABABAAPP 24242244 METHODS METHODS:: METHODS
METHODS:: DISDISDISDISPPPPLALALALAYYYY____NONONONO____OFOFOFOF____EMPEMPEMPEMPLLLLOYEEOYEEOYEEOYEESSSS....
PROTECTED
PROTECTED SECTION.SECTION.
PROTECTED
PROTECTED SECTION.SECTION.
DATA
DATA ::
DATA
DATA :: G_G_G_G_NONONONO____OFOFOFOF____EMPEMPEMPEMPLLLLOYEEOYEEOYEEOYEESSSS TYPETYPETYPETYPE IIII....
PRIVATE
PRIVATE SECTION.SECTION.
PRIVATE
PRIVATE SECTION.SECTION.
DATA
DATA
DATA
DATA G_G_G_G_EMPEMPEMPEMPLLLLOYEE TYPE TOYEE TYPE TOYEE TYPE TOYEE TYPE T____EMPEMPEMPEMPLLLLOYEE.OYEE.OYEE.OYEE.
ENDCLASS.
ENDCLASS. CLASSCLASS
ENDCLASS.
ENDCLASS. CLASSCLASS CL_CL_CL_CL_EMPEMPEMPEMPLLLLOYEEOYEEOYEEOYEE IMPLEMENTATION.IMPLEMENTATION.IMPLEMENTATION.IMPLEMENTATION.
METHOD
METHOD
METHOD
METHOD CCCCONONONONSSSSTRTRTRTRUCUCUCUCTORTORTORTOR.... G_
G_EMPEMPLLOYEEOYEE
G_
G_EMPEMPLLOYEE-OYEE--NO =-NO =NO =NO = IIIIMMMM____EMPEMPEMPEMPLLLLOYEEOYEEOYEEOYEE____NO.NO.NO.NO.
G_
G_EMPEMPLLOYEEOYEE
G_
G_EMPEMPLLOYEE-OYEE--N-NNNAAAAME =ME =ME =ME = IIIIMMMM____EMPEMPEMPEMPLLLLOYEEOYEEOYEEOYEE____NNNNAAAAME.ME.ME.ME.
G_
G_NONO__OFOF__EMPEMPLLOYEEOYEESS == G_G_NONO__OFOF__EMPEMPLLOYEEOYEESS + 1.+ 1.
G_
G_NONO__OFOF__EMPEMPLLOYEEOYEESS == G_G_NONO__OFOF__EMPEMPLLOYEEOYEESS + 1.+ 1.
ENDMETHOD.
ENDMETHOD.
ENDMETHOD.
OOPS in ABAP OOPS in ABAP O
OOOPPSSiinnABABAAPP 25252255
Class Im
Class Im
plementatio
plementatio
n
n
Class Implementation
-Class Implementation -
-> An Example
-> An Example
> An Example
> An Example
CLASSCLASS
CLASS
CLASS CL_CL_CL_CL_EMPEMPEMPEMPLLLLOYEEOYEEOYEEOYEE IMPLEMENTATION.IMPLEMENTATION.IMPLEMENTATION.IMPLEMENTATION.
METHOD
METHOD
METHOD
METHOD CCCCONONONONSSSSTRTRTRTRUCUCUCUCTORTORTORTOR....
G_
G_EMPEMPLLOYEEOYEE G_
G_EMPEMPLLOYEE-OYEE--NO =-NO =NO =NO = IIIIMMMM____EMPEMPEMPEMPLLLLOYEEOYEEOYEEOYEE____NO.NO.NO.NO. G_
G_EMPEMPLLOYEEOYEE G_
G_EMPEMPLLOYEE-OYEE--N-NNNAAAAME =ME =ME =ME = IIIIMMMM____EMPEMPEMPEMPLLLLOYEEOYEEOYEEOYEE____NNNNAAAAME.ME.ME.ME. G_
G_NONO__OFOF__EMPEMPLLOYEEOYEESS == G_G_NONO__OFOF__EMPEMPLLOYEEOYEESS + 1.+ 1. G_
G_NONO__OFOF__EMPEMPLLOYEEOYEESS == G_G_NONO__OFOF__EMPEMPLLOYEEOYEESS + 1.+ 1.
ENDMETHOD. ENDMETHOD. ENDMETHOD. ENDMETHOD. METHOD METHOD METHOD
METHOD DISDISDISDISPPPPLALALALAYYYY____EMPEMPEMPEMPLLLLOYEE.OYEE.OYEE.OYEE. WR
WRIITE:/ µEmployee Number¶TE:/ µEmployee Number¶,G_,G_EMPEMPLLOYEEOYEE__NO.NO. WR
WRIITE:/ µEmployee Number¶TE:/ µEmployee Number¶,G_,G_EMPEMPLLOYEEOYEE__NO.NO. WR
WRIITE:/ 'Employee Name'TE:/ 'Employee Name',, G_G_EMPEMPLLOYEEOYEE WR
WRIITE:/ 'Employee Name'TE:/ 'Employee Name',, G_G_EMPEMPLLOYEE-OYEE--N-NNNAAAAME.ME.ME.ME.
ENDMETHOD. ENDMETHOD. ENDMETHOD. ENDMETHOD. METHOD METHOD METHOD
METHOD DISDISDISDISPPPPLALALALAYYYY____NONONONO____OFOFOFOF____EMPEMPEMPEMPLLLLOYEEOYEEOYEEOYEESSSS.... WR
WRIITE:/ 'Number of employees is : 'TE:/ 'Number of employees is : ',, WR
WRIITE:/ 'Number of employees is : 'TE:/ 'Number of employees is : ',, G_
G_NONO__OFOF__EMPEMPLLOYEEOYEESS.. G_
G_NONO__OFOF__EMPEMPLLOYEEOYEESS..
ENDMETHOD. ENDMETHOD. ENDMETHOD. ENDMETHOD. ENDCLASS ENDCLASS ENDCLASS ENDCLASS....
OOPS in ABAP OOPS in ABAP O
OOOPPSSiinnABABAAPP 26262266
DATA
DATA :: G_G_EMPEMPLLOOYYEEEE1 1 TTYYPPEE RREEFF TTOO LCL_LCL_EMPEMPLLOYEE.OYEE.
START
START--OFOF--SELECTION.SELECTION. C
CREREAATE OBJETE OBJECCTT G_G_EMPEMPLLOYEE1OYEE1
EXPORTING
EXPORTING I
IMM__EMPEMPLLOYEEOYEE__NO = 1NO = 1
I
IMM__EMPEMPLLOYEEOYEE__NNAAME = 'John Jones'.ME = 'John Jones'.
CALL
CALL METHOD METHOD G_G_EMPEMPLLOYEE1->OYEE1->DISDISPPLALAYY__EMPEMPLLOYEE.OYEE.
CALL
CALL METHOD METHOD G_G_EMPEMPLLOYEE1->OYEE1->DISDISPPLALAYY__
NO
OOPS in ABAP OOPS in ABAP O
OOPS in ABAP OOPS in ABAP O
OOOPPSSiinnABABAAPP 28282288
CLASS COMPONENTS contd«
CLASS COMPONENTS contd«
CLASS COMPONENTS contd«
CLASS COMPONENTS contd«
Events Events Events Events Events are used to trigger eventEvents are used to trigger eventEvents are used to trigger event-Events are used to trigger event--handler methods in objects-handler methods in objectshandler methods in objectshandler methods in objects
or classes. or classes. or classes. or classes.
When an event is triggered, any no: of handler When an event is triggered, any no: of handler When an event is triggered, any no: of handler When an event is triggered, any no: of handler methods canmethods canmethods canmethods can
be called and the handler determines events to which it want
be called and the handler determines events to which it want
be called and the handler determines events to which it want
be called and the handler determines events to which it want
to react. to react. to react. to react.
Events of a class can be triggered in the mEvents of a class can be triggered in the mEvents of a class can be triggered in the mEvents of a class can be triggered in the methods of sameethods of sameethods of sameethods of same
class using RAISE EVENT statement.
class using RAISE EVENT statement.
class using RAISE EVENT statement.
class using RAISE EVENT statement.
A method of same or different class can be declared A method of same or different class can be declared A method of same or different class can be declared A method of same or different class can be declared as anas anas anas an
event handler method f
event handler method for the eventor the event <<evt> of classevt> of class <<class> byclass> by
event handler method f
event handler method for the eventor the event <<evt> of classevt> of class <<class> byclass> by
giving the addition
giving the addition
giving the addition
giving the addition
FOR EVENT
FOR EVENT <<evt> OFevt> OF <<class>.class>.
FOR EVENT
FOR EVENT <<evt> OFevt> OF <<class>.class>.
The link betwThe link betwThe link betwThe link between handler een handler een handler een handler and trigger is established at runtimeand trigger is established at runtimeand trigger is established at runtimeand trigger is established at runtime
using the statement
using the statement SET HANDLER.SET HANDLER.
using the statement
OOPS in ABAP OOPS in ABAP O
OOOPPSSiinnABABAAPP 29292299
Handling and Triggering Events
Handling and Triggering Events
Handling and Triggering Events
Handling and Triggering Events
To trigger an event, a class mustTo trigger an event, a class mustTo trigger an event, a class mustTo trigger an event, a class must
a) declare the event in declaration part
a) declare the event in declaration part
a) declare the event in declaration part
a) declare the event in declaration part
b) trigger the event in one of its
b) trigger the event in one of its events.events.
b) trigger the event in one of its
b) trigger the event in one of its events.events.
Declaring Events Declaring Events Declaring Events Declaring Events
To declare instance events,To declare instance events,To declare instance events,To declare instance events,
EVENTS
EVENTS <<evt> EXPORTING.. VALUE(evt> EXPORTING.. VALUE(<<ee
EVENTS
EVENTS <<evt> EXPORTING.. VALUE(evt> EXPORTING.. VALUE(<<eeiiii>) TYPE type>) TYPE type>) TYPE type>) TYPE type
[OPTIONAL]. [OPTIONAL]. [OPTIONAL]. [OPTIONAL].
To declare static To declare static To declare static To declare static events,events,events,events,
CLASS
CLASS
CLASS-CLASS--EVENTS-EVENTSEVENTSEVENTS <<<<evt>..evt>..evt>..evt>..
Triggering Events Triggering Events Triggering Events Triggering Events
Instance events can be triggered by any method in the classInstance events can be triggered by any method in the classInstance events can be triggered by any method in the classInstance events can be triggered by any method in the class
while static events can be done using only static
while static events can be done using only static methods.methods.
while static events can be done using only static
while static events can be done using only static methods.methods.
RAISE EVENT
RAISE EVENT <<evt> EXPORTINGevt> EXPORTING <<ee
RAISE EVENT
OOPS in ABAP OOPS in ABAP O OOOPPSSiinnABABAAPP 30303300 Handling Events Handling Events Handling Events Handling Events
To handle an event, a method mustTo handle an event, a method mustTo handle an event, a method mustTo handle an event, a method must
a) be defined as an event handler method for that event.
a) be defined as an event handler method for that event.
a) be defined as an event handler method for that event.
a) be defined as an event handler method for that event.
b) be registered at runtime for the event.
b) be registered at runtime for the event.
b) be registered at runtime for the event.
b) be registered at runtime for the event.
To declare an event handler method, use To declare an event handler method, use To declare an event handler method, use To declare an event handler method, use following statement.following statement.following statement.following statement.
METHODS
METHODS <<meth> FOR EVENTmeth> FOR EVENT <<evt> OFevt> OF <<cif> IMPORTINGcif> IMPORTING
METHODS
METHODS <<meth> FOR EVENTmeth> FOR EVENT <<evt> OFevt> OF <<cif> IMPORTINGcif> IMPORTING <
<ee <
<eeiiii> => => => = <<<<f f f f iiii> (for instance method).> (for instance method).> (for instance method).> (for instance method).
To register event handler method, use the To register event handler method, use the To register event handler method, use the To register event handler method, use the following statement.following statement.following statement.following statement.
SET HANDLER..
SET HANDLER.. <<h>.. FOR..h>.. FOR..
SET HANDLER..
SET HANDLER.. <<h>.. FOR..h>.. FOR..
After the RAISE EVENT statement, all registered event handler After the RAISE EVENT statement, all registered event handler After the RAISE EVENT statement, all registered event handler After the RAISE EVENT statement, all registered event handler
methods are executed before the next statement is
methods are executed before the next statement is processed.processed.
methods are executed before the next statement is
methods are executed before the next statement is processed.processed.
OOPS in ABAP OOPS in ABAP O OOOPPSSiinnABABAAPP 31313311
Event Handling
Event Handling
Event Handling
-Event Handling -
-> An example
-> An example
> An example
> An example
REPORT Z
REPORT ZGAS_GAS_NEW .NEW .
REPORT Z
REPORT ZGAS_GAS_NEW .NEW .
CLASS
CLASS countercounter DDEFEFIINNIITTIION.ON. CLASS
CLASS countercounter DDEFEFIINNIITTIION.ON.
P
PUUBBLICLIC SSEECCTTIION.ON.
P
PUUBBLICLIC SSEECCTTIION.ON.
METHO
METHODSDS incrementincrement__counter.counter.
METHO
METHODSDS incrementincrement__counter.counter.
EVENTS
EVENTS ccritiriticcalal _v _valuealue EXPORTINGEXPORTING
EVENTS
EVENTS ccritiriticcalal _v _valuealue EXPORTINGEXPORTING
v
value(exalue(exccess)ess) TYPETYPE ii..
v
value(exalue(exccess)ess) TYPETYPE ii..
PR
PRIVAIVATETE SSEECCTTIION.ON.
PR
PRIVAIVATETE SSEECCTTIION.ON.
DA
DATTAA: : count count TYPE TYPE ii,, DA
DATTAA: : count count TYPE TYPE ii,, threshold
threshold TYPETYPE ii VALUE VALUE 1010..
threshold
threshold TYPETYPE ii VALUE VALUE 1010..
EN
ENDCLASSDCLASS..
EN
ENDCLASSDCLASS..
CLASS
CLASS handlerhandler DDEFEFIINNIITTIION.ON. CLASS
CLASS handlerhandler DDEFEFIINNIITTIION.ON.
P
PUUBBLICLIC SSEECCTTIION.ON.
P
PUUBBLICLIC SSEECCTTIION.ON.
METHODS
METHODS handlehandle _ _ exexccessess FOR FOR EVENTEVENT ccritiriticcalal _v _valuealue
METHODS
METHODS handlehandle _ _ exexccessess FOR FOR EVENTEVENT ccritiriticcalal _v _valuealue
OF
OF ccounterounter IMPORTINGIMPORTING exexccessess..
OF
OF ccounterounter IMPORTINGIMPORTING exexccessess..
EN
ENDCLASSDCLASS..
EN
OOPS in ABAP OOPS in ABAP O
OOOPPSSiinnABABAAPP 32323322
CLASS
CLASS countercounter IIMPMPLLEMENTEMENTAATTIION.ON.
CLASS
CLASS countercounter IIMPMPLLEMENTEMENTAATTIION.ON.
METHO
METHODD incrementincrement__counter.counter.
METHO
METHODD incrementincrement__counter.counter.
DA
DATTAA diff TYPE i.diff TYPE i.
DA
DATTAA diff TYPE i.diff TYPE i.
ADD
ADD 1 TO count.1 TO count.
ADD
ADD 1 TO count.1 TO count.
I
IF count > threshold.F count > threshold.
I
IF count > threshold.F count > threshold.
diff = count
diff = count
diff = count
-diff = count --- threshold.threshold.tthhrreesshhoolldd..
RAISE
RAISE EVENTEVENT ccritiriticcalal _v _valuealue
RAISE
RAISE EVENTEVENT ccritiriticcalal _v _valuealue
EXPORTING
EXPORTING exexccess = diffess = diff..
EXPORTING
EXPORTING exexccess = diffess = diff..
EN ENDIDIF.F. EN ENDIDIF.F. EN ENDDMETHOMETHODD.. EN ENDDMETHOMETHODD.. EN ENDCLASSDCLASS EN ENDCLASSDCLASS....
OOPS in ABAP OOPS in ABAP O
OOOPPSSiinnABABAAPP 33333333
CLASS
CLASS handlerhandler IIMPMPLLEMENTEMENTAATTIION.ON. CLASS
CLASS handlerhandler IIMPMPLLEMENTEMENTAATTIION.ON. METHOD
METHOD handlehandle _ _ exexccessess..
METHOD
METHOD handlehandle _ _ exexccessess..
WRITE
WRITE: : / '/ 'EExxccess is', exess is', exccessess..
WRITE
WRITE: : / '/ 'EExxccess is', exess is', exccessess..
ENDMETHOD. ENDMETHOD. ENDMETHOD. ENDMETHOD. EN ENDCLASSDCLASS.. EN ENDCLASSDCLASS.. DA
DATTAA: r1 TYPE REF TO counter: r1 TYPE REF TO counter,, DA
DATTAA: r1 TYPE REF TO counter: r1 TYPE REF TO counter,,
h1 TYPE REF TO
h1 TYPE REF TO handler.handler.
h1 TYPE REF TO
h1 TYPE REF TO handler.handler.
S
STTAARTRT S
STTAART-RT--OF-OFOF-OF---SSSSEEEELLLLEEEECCCCTTTTIIIION.ON.ON.ON. C
CREREAATE OBJETE OBJECCT: r1T: r1,, h1.h1. C
CREREAATE OBJETE OBJECCT: r1T: r1,, h1.h1. SET
SET HANDLER HANDLER h1h1
SET
SET HANDLER HANDLER h1-h1-->handle->handle>handle>handle _ _ _ _ exexexexccccessessessess FOR FOR FOR FOR ALL ALL ALL ALL INSTANCES.INSTANCES.INSTANCES.INSTANCES. D
DO 20 TO 20 TIIMEMESS.. D
DO 20 TO 20 TIIMEMESS.. CALL
CALL METHOMETHODD r1r1 CALL
CALL METHOMETHODD r1-r1-->increment->increment>increment>increment____counter.counter.counter.counter.
EN
ENDDDDO.O.
EN
OOPS in ABAP OOPS in ABAP O
OOPS in ABAP OOPS in ABAP O OOOPPSSiinnABABAAPP 35353355
Constructors
Constructors
Constructors
Constructors
Special methods called automatically by the system to set theSpecial methods called automatically by the system to set theSpecial methods called automatically by the system to set theSpecial methods called automatically by the system to set the
starting state of an object or class.
starting state of an object or class.
starting state of an object or class.
starting state of an object or class.
Called when a class is instantiated.Called when a class is instantiated.Called when a class is instantiated.Called when a class is instantiated.
Types of Constructors Types of Constructors Types of Constructors Types of Constructors Instance constructors Instance constructors Instance constructors Instance constructors
Declared using keyword METHODS CONSTRUCTORDeclared using keyword METHODS CONSTRUCTORDeclared using keyword METHODS CONSTRUCTORDeclared using keyword METHODS CONSTRUCTOR
Used to initialize instance attributes.Used to initialize instance attributes.Used to initialize instance attributes.Used to initialize instance attributes.
Static Constructors Static Constructors Static Constructors Static Constructors
Declared using CLASSDeclared using CLASSDeclared using CLASS-Declared using CLASS--METHODS CLASS CONSTRUCTOR.-METHODS CLASS CONSTRUCTOR.METHODS CLASS CONSTRUCTOR.METHODS CLASS CONSTRUCTOR.
Used to initialize static attributes.Used to initialize static attributes.Used to initialize static attributes.Used to initialize static attributes.
Constructor implementation is similar to a methodConstructor implementation is similar to a methodConstructor implementation is similar to a methodConstructor implementation is similar to a method
implementation.
implementation.
implementation.
OOPS in ABAP OOPS in ABAP O OOOPPSSiinnABABAAPP 36363366
Inheritance
Inheritance
Inheritance
Inheritance
The statement isThe statement isThe statement isThe statement is CLASS
CLASS <<subclass> DEFINTION INHERITING FROMsubclass> DEFINTION INHERITING FROM CLASS
CLASS <<subclass> DEFINTION INHERITING FROMsubclass> DEFINTION INHERITING FROM
< <superclass>.superclass>. < <superclass>.superclass>.
A class can have more than one A class can have more than one A class can have more than one A class can have more than one subclass, but may havesubclass, but may havesubclass, but may havesubclass, but may have only one superclass(single inheritance).
only one superclass(single inheritance). only one superclass(single inheritance). only one superclass(single inheritance).
OBJECT OBJECT C1 C1 C2 C2
OOPS in ABAP OOPS in ABAP O OOOPPSSiinnABABAAPP 37373377
Inheritance contd«
Inheritance contd«
Inheritance contd«
Inheritance contd«
When subclasses inherit from superclass, which itself aWhen subclasses inherit from superclass, which itself aWhen subclasses inherit from superclass, which itself aWhen subclasses inherit from superclass, which itself a subclass of another class, all classes form inheritance subclass of another class, all classes form inheritance subclass of another class, all classes form inheritance subclass of another class, all classes form inheritance tree. tree. tree. tree. Redefining Methods Redefining Methods Redefining Methods Redefining Methods
Use the addition REDEFINITION in Use the addition REDEFINITION in Use the addition REDEFINITION in Use the addition REDEFINITION in METHODSMETHODSMETHODSMETHODS statement to redefin
statement to redefine e public or protected instancepublic or protected instance statement to redefin
statement to redefine e public or protected instancepublic or protected instance method in a subclass. method in a subclass. method in a subclass. method in a subclass.
The method retains the name and interface, but with aThe method retains the name and interface, but with aThe method retains the name and interface, but with aThe method retains the name and interface, but with a new implementation.
new implementation. new implementation. new implementation.
OOPS in ABAP OOPS in ABAP O OOOPPSSiinnABABAAPP 38383388
Interfaces
Interfaces
Interfaces
Interfaces
Exclusively describes the external point of contact, butExclusively describes the external point of contact, butExclusively describes the external point of contact, butExclusively describes the external point of contact, but don¶t contain any implementation part.
don¶t contain any implementation part. don¶t contain any implementation part. don¶t contain any implementation part.
Has only declaration part, in the public section of Has only declaration part, in the public section of Has only declaration part, in the public section of Has only declaration part, in the public section of classes. classes. classes. classes.
A class can implement any number of interfaces and A class can implement any number of interfaces and A class can implement any number of interfaces and A class can implement any number of interfaces and
interface can be implemented by any number of classes. interface can be implemented by any number of classes. interface can be implemented by any number of classes. interface can be implemented by any number of classes.
Interface resolutiInterface resolutiInterface resolutiInterface resolution on on on operator(~operator(~operator(~operator(~) enables ) enables ) enables ) enables to accessto accessto accessto access interface compone
interface components using nts using an object referencean object reference interface compone
interface components using nts using an object referencean object reference belonging to the class implementing the interface. belonging to the class implementing the interface. belonging to the class implementing the interface. belonging to the class implementing the interface.
OOPS in ABAP OOPS in ABAP O OOOPPSSiinnABABAAPP 39393399
Defining Interfaces
Defining Interfaces
Defining Interfaces
Defining Interfaces
Use the statementUse the statementUse the statementUse the statement
INTERFACE
INTERFACE <<intf>intf> INTERFACE
INTERFACE <<intf>intf> ---ENDINTERFACE. ENDINTERFACE. ENDINTERFACE. ENDINTERFACE.
Can be defined either globally in R/3 repository or Can be defined either globally in R/3 repository or Can be defined either globally in R/3 repository or Can be defined either globally in R/3 repository or locally in ABAP program.
locally in ABAP program. locally in ABAP program. locally in ABAP program.
You can define the same components in an interfaceYou can define the same components in an interfaceYou can define the same components in an interfaceYou can define the same components in an interface as in a class. as in a class. as in a class. as in a class.
ComponenComponenComponenComponents don¶t have ts don¶t have ts don¶t have ts don¶t have to be assigned individually toto be assigned individually toto be assigned individually toto be assigned individually to a visibility section. a visibility section. a visibility section. a visibility section.
Interfaces don¶t have an implementation part, since their Interfaces don¶t have an implementation part, since their Interfaces don¶t have an implementation part, since their Interfaces don¶t have an implementation part, since their methods are implemented in the class that implements it. methods are implemented in the class that implements it. methods are implemented in the class that implements it. methods are implemented in the class that implements it.
OOPS in ABAP OOPS in ABAP O OOOPPSSiinnABABAAPP 40404400
Implementing Interfaces
Implementing Interfaces
Implementing Interfaces
Implementing Interfaces
Use in the declaration part of the Use in the declaration part of the Use in the declaration part of the Use in the declaration part of the class (public section),class (public section),class (public section),class (public section), INTERFACES
INTERFACES <<intf>.intf>. INTERFACES
INTERFACES <<intf>.intf>.
During implementation, components are added to other During implementation, components are added to other During implementation, components are added to other During implementation, components are added to other componen
components in ts in the public section.the public section. componen
components in ts in the public section.the public section.
The class must implement the methods of all interfacesThe class must implement the methods of all interfacesThe class must implement the methods of all interfacesThe class must implement the methods of all interfaces implemented in it . implemented in it . implemented in it . implemented in it .
The implemThe implemThe implemThe implementation part entation part entation part entation part of the class must contain of the class must contain of the class must contain of the class must contain aaaa method implementation for each interface method method implementation for each interface method method implementation for each interface method method implementation for each interface method
<
<imeth>:imeth>:
<
<imeth>:imeth>:
METHOD
METHOD <<intf~imeth>intf~imeth> METHOD
METHOD <<intf~imeth>intf~imeth> ---ENDMETHOD. ENDMETHOD. ENDMETHOD. ENDMETHOD.
OOPS in ABAP OOPS in ABAP O
OOOPPSSiinnABABAAPP 41414411
Advanta
Advanta
ges of OOPS in
ges of OOPS in
ABAP
ABAP
Advanta
Advanta
ges of OOPS in
ges of OOPS in
ABAP
ABAP
The implementation of object-oriented elements inThe implementation of object-oriented elements in
ABAP language has considerably increased response ABAP language has considerably increased response
times. times.
Use of OOPS in ABAP helps Use of OOPS in ABAP helps to have a better controlto have a better control of development complexity, a better means for
of development complexity, a better means for encapsulation and extensibility.
encapsulation and extensibility.
Reusability of the objects will Reusability of the objects will reduce the coding effortreduce the coding effort and helps in utilizing the existing code for other
and helps in utilizing the existing code for other programs.
OOPS in ABAP OOPS in ABAP O
OOOPPSSiinnABABAAPP 42424422
Object Orientatio
Object Orientatio
n T
n T
ools in ABAP
ools in ABAP
Object Orientatio
Object Orientatio
n T
n T
ools in ABAP
ools in ABAP
ABAP Class Builder ABAP Class Builder ABAP Class Builder ABAP Class Builder
Transaction Code:Transaction Code:TTrraannssaaccttiioon n CCooddee:: SE24.SSSE24.EE2244..
Allows you to create and maintain global classes Allows you to create and maintain global classes Allows you to create and maintain global classes Allows you to create and maintain global classes
and interfaces. and interfaces. and interfaces. and interfaces. Features Features Features Features
Display an overview of global data types and their Display an overview of global data types and their Display an overview of global data types and their Display an overview of global data types and their
relationships. relationships. relationships. relationships.
Create and specify attributes, methods and eventsCreate and specify attributes, methods and eventsCreate and specify attributes, methods and eventsCreate and specify attributes, methods and events
of global classes and interfaces. of global classes and interfaces. of global classes and interfaces. of global classes and interfaces.
Create internal types in a class.Create internal types in a class.Create internal types in a class.Create internal types in a class.
OOPS in ABAP OOPS in ABAP O
OOPS in ABAP OOPS in ABAP O
OOOPPSSiinnABABAAPP 44444444
HOW TO USE ALV USING OOPS HOW TO USE ALV USING OOPS HOW TO USE ALV USING OOPS HOW TO USE ALV USING OOPS
OOPS in ABAP OOPS in ABAP O OOOPPSSiinnABABAAPP 45454455 Tcode: SE38 Tcode: SE38 C
OOPS in ABAP OOPS in ABAP O
OOOPPSSiinnABABAAPP 46464466
G
OOPS in ABAP OOPS in ABAP O
OOOPPSSiinnABABAAPP 47474477
Add a
OOPS in ABAP OOPS in ABAP O
OOOPPSSiinnABABAAPP 48484488
G
OOPS in ABAP OOPS in ABAP O
OOOPPSSiinnABABAAPP 49494499
Declare
OOPS in ABAP
OOPS in ABAP
O
OOOPPSSiinnAABBAAPP 55505000
Fill internal table with list data to
OOPS in ABAP OOPS in ABAP O
OOOPPSSiinnABABAAPP 51515511
I
In PBO of the flow logic, wn PBO of the flow logic, write a module and inside the modulerite a module and inside the module
write the code write the code
OOPS in ABAP OOPS in ABAP O
OOOPPSSiinnABABAAPP 52525522
I
If ALVf ALV GGrid instance not exist.rid instance not exist.
C
OOPS in ABAP OOPS in ABAP O
OOPS in ABAP OOPS in ABAP O
OOOPPSSiinnABABAAPP 54545544
C
OOPS in ABAP OOPS in ABAP O
OOOPPSSiinnABABAAPP 55555555
C
OOPS in ABAP OOPS in ABAP O