Вы находитесь на странице: 1из 31

ABAP objects

ABAP Objects

Objectives

In this Chapter you will learn...


About ABAP Objects
About Object orientation

ABAP Objects

ABAP Objects is fairly a new concept in R/3. The term has two
meanings.
It stands for the entire ABAP runtime environment.
and
It represents the object-oriented extension of the ABAP
language

ABAP Objects

ABAP Runtime Environment

The ABAP Workbench allows you to create R/3


Repository objects such as programs, authorization
objects, lock objects, Customizing objects, and so on.

Using function modules, you can encapsulate


functions in separate programs with a defined
interface.

The Business Object Repository (BOR) allows you to


create SAP Business Objects for internal and external
use (DCOM/CORBA).

ABAP Objects

The Object-oriented Language Extension

ABAP Objects is a complete set of object-oriented


statements that has been introduced into the ABAP
language.

This object-oriented extension of ABAP builds on the


existing language, and is fully compatible with it.

You can use ABAP Objects in existing programs, and


can also use "conventional" ABAP in new ABAP Objects
programs.

ABAP Objects

The Object-oriented Language Extension...


ABAP Objects supports object-oriented programming
The object-oriented enhancement of ABAP is based on the
models of Java and C++. It is compatible with external
object interfaces such as DCOM and CORBA
SAP Business Objects and GUI objects - already objectoriented themselves - will also profit from being
incorporated in ABAP Objects.

ABAP Objects
Object-Orientation.
Object orientation (OO), or to be more precise, objectoriented programming, is a problem-solving method in
which the software solution reflects objects in the real
world .
Objects
An object is a section of source code that contains
data and provides services.
The data forms the attributes of the object.
The services are known as methods (also known as
operations or functions).

ABAP Objects

Uses of OO.
The main difference between real object orientation and
function groups is that although a program can work with
the instances of several function groups at the same
time, it cannot work with several instances of a single
function group.
This requirement is met by object orientation. ABAP
Objects allows you to define data and functions in
classes instead of function groups. Using classes, an
ABAP program can work with any number of instances
(objects) based on the same template.

ABAP Objects

Classes
Classes describe objects.
From a technical point of view, objects are runtime
instances of a class.
In theory, you can create any number of objects based
on a single class.
Each instance (object) of a class has a unique identity
and its own set of values for its attributes.

ABAP Objects

Classes
Classes describe objects.
From a technical point of view, objects are runtime
instances of a class.
In theory, you can create any number of objects based
on a single class.
Each instance (object) of a class has a unique identity
and its own set of values for its attributes.

ABAP Objects

To Create a Class
Go to Transaction SE80

ABAP Objects

To Create a Class
Then specify whether you want to create a class or interface.

ABAP Objects

To Create Class
Instance is nothing but a copy of class which is called as
object. We will discuss about the Public, private class in
the following slide.
Instance of class
Class declaration

ABAP Objects

Structure of a Class
A class contains components
Each component is assigned to a visibility section
Classes implement methods

ABAP Objects
Class Components
The components of a class make up its contents.
All components are declared in the declaration part of
the class.
The components define the attributes of the objects in a
class.
When you define the class, each component is assigned
to one of the three visibility sections, which define the
external interface of the class.
All of the components of a class are visible within the
class. All components are in the same namespace.
This means that all components of the class must have
names that are unique within the class.

ABAP Objects

Attributes
Attributes are internal data fields within a class that
can have any ABAP data type.
The state of an object is determined by the contents of
its attributes.
One kind of attribute is the reference variable.
Reference variables allow you to create and address
objects. Reference variables can be defined in classes,
allowing you to access objects from within a class.

ABAP Objects

Method
Methods are internal procedures in a class that define
the behavior of an object.
They can access all of the attributes of a class. This
allows them to change the data content of an object.
They also have a parameter interface, with which
users can supply them with values when calling them,
and receive values back from them
The private attributes of a class can only be changed
by methods in the same class.

ABAP Objects

Method...
Methods are internal procedures in a class that define
the behavior of an object.
They can access all of the attributes of a class. This
allows them to change the data content of an object.
They also have a parameter interface, with which
users can supply them with values when calling them,
and receive values back from them
The private attributes of a class can only be changed
by methods in the same class.

ABAP Objects

Method
The definition and parameter interface of a method is
similar to that of function modules.
You define a method <met> in the definition part of a
class and implement it in the implementation part using
the following processing block:
METHOD <meth>.
...
ENDMETHOD.
You can declare local data types and objects in
methods in the same way as in other ABAP procedures
(subroutines and function modules). You call methods
using the CALL METHOD statement.

ABAP Objects

Method
The definition and parameter interface of a method is
similar to that of function modules.
You define a method <met> in the definition part of a
class and implement it in the implementation part using
the following processing block:
METHOD <meth>.
...
ENDMETHOD.
You can declare local data types and objects in methods
in the same way as in other ABAP procedures (subroutines
and function modules). You call methods using the CALL
METHOD statement.
CALL METHOD <ObjName> -> <Method>

ABAP Objects
Method

Instance Methods
You declare instance methods using the METHODS
statement. They can access all of the attributes of a
class, and can trigger all of the events of the class

Static Methods
You declare static methods using the CLASSMETHODS statement. They can only access static
attributes and trigger static events.

ABAP Objects

Classes Visibility Section.


You can divide the declaration part of a class into up to three
visibility areas:
CLASS <class> DEFINITION.
PUBLIC SECTION.
...
PROTECTED SECTION.
...
PRIVATE SECTION.
...
ENDCLASS.

ABAP Objects

To Create a Method.
Double click on the object Name(ZNDC) and it will take
you the following Screen, where you define the level,
visibility, Description etc. for particular method in a
class.

ABAP Objects

To Implement your method.


Double click on the Method to implement your
method.
Click to implement your
method

ABAP Objects

To Implement your method.

ABAP Objects

Classes Visibility Section.

Public Section
All of the components declared in the
public section are accessible to all
users of the class, and to the methods
of the class and any classes that inherit
from it. The public components of the
class form the interface between the
class and its users.

ABAP Objects

Classes Visibility Section.

Private Section
Components that you declare in the
private section are only visible in the
methods of the same class. The private
components are not part of the
external interface of the class.

ABAP Objects

Classes Visibility Section.

Protected Section
All of the components in the protected section can
access the components from the public section. In
turn, they can be accessed by the components of
the private section.

ABAP Objects

Classes Visibility Section.

Public Section

ABAP Objects
Public Section of the Class, which is visible & accessible to all users of the class.

ABAP Objects

Summary
ABAP Objects represents OO extension of ABAP
Programming
Language
Class describes a Object
Object is a instance of a class
Each object provides services through methods

Вам также может понравиться