0% found this document useful (0 votes)
24 views7 pages

Oo

This document discusses object-oriented concepts in ABAP including abstraction, encapsulation, inheritance, and polymorphism. It provides examples of implementing these concepts through ABAP classes and methods. Local classes in ABAP can be defined similarly to other object-oriented languages with public, private, and protected methods and data. Global classes in SE24 allow for instance-specific and static methods to be defined.

Uploaded by

Akhila
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views7 pages

Oo

This document discusses object-oriented concepts in ABAP including abstraction, encapsulation, inheritance, and polymorphism. It provides examples of implementing these concepts through ABAP classes and methods. Local classes in ABAP can be defined similarly to other object-oriented languages with public, private, and protected methods and data. Global classes in SE24 allow for instance-specific and static methods to be defined.

Uploaded by

Akhila
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 7

ABAP OBJECTS(Object Oriented ABAP)

java is by birth OO LANGUAGE.

abap is by birth procedural language,now it is oo.

Object Orientaton :

It is a problem solving method in which solution is represented into real world


object.

A language is object oriented,when it supports oo concepts such as :

1.Abstraction
2 Encapsulation
3)Inheritance
4)Polymorphism

---------------
1.Abstraction :
---------------
Represents only the essential features and hide the unneccesary
details,
to let every one enjoy the functionality with out understanding the internal
details.

ex : fm : gui_upload

open se24 class cl_gui_frontend_services

find -->gui_upload u find function module only.

note : abstraction is to be supported through methods only.

-----------------
2)Encapsulation :
-----------------

Encapsulate,the set of attributes/charecterstics/data and the associated


functionalities/methods of an object in a single business unit called class and
purpose to restrict the unauthorized access.

note : the accessibility depends on the access specifiers/visibility sections.

1.PUBLIC SECTION : can be accessed from outside the class also.


so that methods are always public so that can be called
outside of the class.
2. PRIVATE SECTION : cannot be accessed out side of the class,so that data should
be private.

3.PROTECTED SECTION : limited access

can be accessed only by the subclasses and if reqd certain data can be protected.

note : default visibility section is PRIVATE.

-----------
Inheritance :
------------
(super/base class)one class completely re-used in other
class(sub class).

note : the subclass can re-implement the super class methods if reqd,and it can add
its own methods.

note :each class by default final,final classes cannot have subclasses.

POLYMOPHISM :
-------------

poly--many
morphism---forms(implementations/functionalities)

i.e. having many implementations for the same method.

note : polymorphism is supported through interfaces.


interface is set of public methods with no implementation.
and the same interface can be implemented by any no of classes.
each class with a different implementation.

interface : methods : CREATE,CHANGE,DISPLAY.

CLASS Customer Implements Interface To Create Customer,


Change Customer,
Display Customer.

CLASS Vendor Implements Interface To Create Vendor,


Change Vendor,
Display Vendor.

CLASSES :

1)LOCAL CLASSES(se38)
2)GLOBAL CLASSES(se24)

LOCAL CLASSES :

CLASS <NAME> DEFINITION

PUBLIC/PRIVATE/PROTECTED.
METHODS : <x>,<y>.

ENDCLASS

CLASS <NAME> IMPLEMENTATION

METHOD <x>.
--
--
ENDMETHOD.

METHOD <y>.
--
--
ENDMETHOD.

ENDCLASS

DATA : <OBJ> TYPE REF TO <NAME>

START-OF-SELECTION.
CREATE OBJECT : <OBJ>.

CALL METHOD-><OBJ>-><x>,<y>.

GLOBAL CLASSES :

se24

ZGCL_CL

enter

instance specific methods---requires object call.

static methods---requires no object to call.

methods :

add_any_tow_integers instance
multiply static

* for add_any_tow_integers
input1 inporting
input2 importing
result exporting

* for multiply

input1 inporting
input2 importing
result exporting

dc on method add_any_tow_integers
result = input1 + input2.

dc on method multiply
result = input1 * input2.

save&activate&F8&check

goto se38

parameters : P_INPUT1 type i,


P_INPUT2 type i.

data : V_RESULT type i.

CALL METHOD ZGCL_CL=>MULTIPLY


EXPORTING
INPUT1 = P_INPUT1
INPUT2 = P_INPUT2
IMPORTING
RESULT = V_RESULT
.

WRITE :/ V_RESULT.

DATA : OBJ TYPE REF TO ZGCL_CL.

CREATE OBJECT OBJ.

CALL METHOD OBJ->ADD_ANY_TOW_INTEGERS


EXPORTING
INPUT1 = P_INPUT1
INPUT2 = P_INPUT2
IMPORTING
RESULT = V_RESULT
.

class/interface : zgcl_air_oprs
methods : add_any_two_ints
enter

system itself creates an object me

me is default object

obect creation is a two step process.


-----------------------------------
1)DATA<OBJE.NAME> TYPE REF TO <CLASS NAME>
2) CREATE OBJECT <OBJ.NAME>

DATA : OBJ TYPE REF TO ZGCL_CL.


CREATE OBJECT OBJ.

function group vs classes :


---------------------------
similarities :
----------------
CLASS is set of methods and data.
and the data i.e. part of private section can be accessed only by the methods of
the same class
where the function group also acts in the same way i.e. which set of function
modules and include
for global data,which can be accessed only by the function modules of the same
function group only.

Variations between function group and class


------------------------------
note : the same function group cannot have more than one instance in same program
where as the
same class can have any no of instances in the same program.

CONSTRUCTOR :
-------------

when the name of the method is constructor it is called automatically at the time
of creating
object itself and it is used to construct the object with the initial values in
general

note : constructor should be always public and it can have only importing
parameters.

create a class in se 24

zgcl_customer

in methods

CREATE IMPORTING PUBLIC


CHANGE IMPORTING PUBLIC
DISPLAY IMPORTING PUBLIC

DC ON CREATE METHOD

call transaction 'xd01'.

DC ON CHANGE METHOD

call transaction 'xd02' and SKIP FIRST SCREEN.

DC ON DISPLAY METHOD

call transaction 'xd03' and SKIP FIRST SCREEN.

THEN CLICK ON CONSTUCTOR BUTTON ON THE TOP

CONSTRUCTOR IS CREATED

parameters

im_kunnr type kunnr.

double click on CONSTRUCTOR method


SET PARAMETER ID 'KUN' FIELD IM_KUNNR.

SAVE AND ACTIVATE THE CLASS.

You might also like