Professional Documents
Culture Documents
INDEX
S.NO.
Topic
Page no.
OOPs concept
2.
Class structure
Object creation
11
References
16
2) Code is re-usable.
3) Data is more secured.
4) Requires less maintenance and hence saves time.
Objects
An object is the structure having data and methods. The attributes of the object is formed
by the data while the services are known as methods.
E.g. Object Customer has all customer related information like name, age, account no. and
methods like salary etc.
Classes
Group of similar objects having similar characteristics is known as classes. We can create
any number of objects based on a single class but each object has a unique identity.
Class types
Classes in ABAP objects can be declared either globally or locally.
1)
Global classes: Global classes are defined in transaction SE24 in the ABAP
workbench. All ABAP programs can access the global classes.
2)
Local classes: The local classes are defined within ABAP program. They can be only
used in the program in which they are defined.
DEFINITION.
CLASS <class>
...
ENDCLASS.
IMPLEMENTATION.
Class Structure:
1) Components: They are declared in the declaration part of the class.
a1 TYPE string.
c) Private section: Data declared in the private section can be accessed by the class
only, but not by its subclasses.
These three visibility areas are the basic for one of the important features of object
orientation i.e. Encapsulation.
Syntax:
CLASS<class>DEFINITION.
PUBLIC
SECTION.
PROTECTED
..
PRIVATE
...
SECTION.
SECTION.
...
ENDCLASS.
Object references.
All the data and methods are accessed through object reference in ABAP program. They are
present in the reference variables.
Class references are defined using
DATA: <OBJ> TYPE REF TO <CLASS>.
After creating reference variable we can create an object by the statement
CREATE OBJECT <obj>.
Declaring Methods
We can declare methods in the declaration part of a class.
To declare instance methods we can use this syntax
METHODS <meth> IMPORTING..
EXPORTING
CHANGING..
RETURNING VALUE..
EXCEPTIONS
While declaring static methods we can use
CLASS-METHODS <meth>
Inheritance: It allows us to derive a new class from an existing class.
Defining METHOD_DISPLAY
ii)
It will create the object from the reference variable through which we can access all the
methods.
I.e. CALL METHOD obj->METHOD_FETCH.
Output:
Now declare the class credit which is the child class of account and is used to credit the
amount.
Class credit
inheriting
class
account
Similarly declare the child class debit which is used to debit the account.
Calling
method
init_bseg
using ->
operator
zlocalclass_dem o.doc
References
1) SDN
2) http://help.sap.com/saphelp_46c/helpdata/en/71/a8a77955bc11d194aa0000e835342
3/frameset.htm
3) SAP R/3 Black book.