You are on page 1of 26

Object Oriented ABAP

WELCOME
To OBJCT ORIENTED ABAP

Abhijit Kulkarni
Sandhya
Ashish Varma
Vinitha
Rachna
Sivam
Sham Sundar
2 The ASPplus Solutions Compan
What are ABAP Objects ?

• ABAP objects are compatible extension


of the existing ABAP language.
• You can use existing ABAP statements
within ABAP objects.
• You can use ABAP objects within
existing programs.
• ABAP objects are fully integrated in
ABAP debugger.
3 The ASPplus Solutions Compan
Elements Of ABAP Objects

• Classes
• Interfaces
• Objects
• Object References
• Inheritance

4 The ASPplus Solutions Compan


Classes

• Classes are templates for objects


• You can define classes globally using the class
builder (Transaction SE24) or locally in an
ABAP program.
• All of the ABAP programs can access the global
classes.
• Local classes and interfaces can only be used in
the program in which they are defined.

5 The ASPplus Solutions Compan


Components of classes

• Attributes
• Methods
• Events
• Types and Constants

6 The ASPplus Solutions Compan


Attributes

• Attributes are data fields in a class. They


can have any ABAP data type. The
content of an attribute determines the
status of an object.
• Instance attributes represents the instance-
dependent status of an object. Instance
attributes are declared using the statement
DATA.

7 The ASPplus Solutions Compan


Attributes

• Static attributes represents the instance-


independent status of the class, which
applies to all instances. Static attributes
exist once for each class. They are
declared using the statement CLASS-
DATA and are retained for the entire
runtime.

8 The ASPplus Solutions Compan


Methods

• Methods are internal procedure in classes.


They can access all attributes of their
class and can thus change the status of an
object.
• Methods have parameter interface which
supplies them with values when they are
called and which they can use to return
values to the caller.

9 The ASPplus Solutions Compan


Methods

• An instance method is declared using the


statement METHODS. It can access all
attributes of a class and trigger all events
of the class.
• Static method is declared using the
statement CLASS-METHODS. It can
access static attributes and trigger only
static events.

10 The ASPplus Solutions Compan


Methods

• Methods can have any number of IMPORTING


parameters and one RETURNING parameter.
• In addition to the regular methods, there are
special methods called CONSTRUCTOR and
CLASS_CONSTRUCTOR, which are called
implicitly when objects are generated or when
class components are called for the first time.

11 The ASPplus Solutions Compan


Events

• Events enable objects or classes to trigger event


handler methods in other objects or classes.
• An instances can only be triggered in instance
methods. Declared using the statement events.
• Static events is declared using the statement
class-events. All methods (instance methods and
static methods) can trigger static events.

12 The ASPplus Solutions Compan


Types and Constants.

• The statements TYPES can be used to


declare self-defined ABAP data types
within a class. Types are not instance-
dependent and exist once for all objects of
a class.

13 The ASPplus Solutions Compan


Class definition and Implementation
• DEFINITION
CLASS <class_name> DEFINITION CLASS
<class_name> DEFINITION DEFERRED.
CLASS <class_name> DEFINITION
LOAD
• IMPLEMENTATION
CLASS class_name>IMPLEMENTATION. …
…….

14
ENDCLASS. The ASPplus Solutions Compan
• Declare the components of the class under
the visibility section
• Visibility section contains three sections
PUBLIC – PROTECTED – PRIVATE .
• The components of the class are Instance
Components,Static Components and
Interfaces.

15 The ASPplus Solutions Compan


CLASS class DEFINITION
DEFERED
• If two classes refer to each other you can
declare the class before you define it.

• CLASS <class_name> DEFINITION


DEFERED.

• This has no corresponding ENDCLASS


statement
16 The ASPplus Solutions Compan
Example

• CLASS C2 DEFINITION DEFERRED.

CLASS C1 DEFINITION.
PUBLIC
SECTION.
DATA O2 TYPE REF TO C2.

ENDCLASS.
17 The ASPplus Solutions Compan
CLASS class DEFINITION LOAD

• If you want to use the global class in the


local class.we have to load it from
library.
• Using CLASS class DEFINITION
LOAD we will load the global class from
the library.

18 The ASPplus Solutions Compan


Example:
CLASS CL_GUI_PICTURE DEFINITION LOAD.
CLASS C1 DEFINITION.
PUBLIC SECTION.
METHODS HANDLER FOR EVENT PICTURE_CLICK
OF
CL_GUI_PICTURE.
ENDCLASS.
CLASS C1 IMPLEMENTATION.
METHOD HANDLER.
ENDMETHOD.
19 The ASPplus Solutions Compan
Interface

• Like classes, you can define interfaces globally


in the class library or locally within an ABAP
program. Interfaces are defined between the
INTERFACE and ENDINTERFACE
statements. They can contain the same
components as classes. An interface’s methods
are not implemented in interface itself, but must
be implemented in the classes that implement
the interface.

20 The ASPplus Solutions Compan


Nested Interfaces

• By using the INTERFACES statement


within the interface definition, you can
define nested interfaces.

21 The ASPplus Solutions Compan


Interface References

• Besides reference variables declared with


respect to a class, ABAP Objects also
provides reference variables declared with
respect to an interface. Those interface
reference variables expose only the
components defined in the interface,
regardless of the implementing class.

22 The ASPplus Solutions Compan


Inheritance

• Inheritance allows you to define classes by


deriving them from existing classes. The new
class adopts or inherits all components of the
existing class. The existing class is called a
super class of the new class.
• A class can have any number of direct
subclasses, but only one super class. ABAP
Objects thus uses single inheritance.

23 The ASPplus Solutions Compan


Objects

• Objects are instance of classes. All transient


objects exist within the context of an internal
session (memory area of an ABAP program).
You can create any number of objects(instances)
for a class. Each one has a unique identity and
its own attributes.
• An object remains intact for as long as it is used
in a program.

24 The ASPplus Solutions Compan


Object References

• Object references are used as pointer to


objects. Object references (the value of
reference variables) are the only way to
access component of an object in an
ABAP program.You can use references to
access attributes and methods, but not
events.

25 The ASPplus Solutions Compan


THANK YOU

26 The ASPplus Solutions Compan