Vous êtes sur la page 1sur 8

OOPS

6.10/6.20

Global Vs. Local Global Class Local Class


class
Accessed from Any Program Only within the
program where it
is defined
Where it stores In the Class Locally in the
repository program where it
is defined
Tools Required to Class builder SE24 With ABAP editor
create SE38
Name Space Must begin Any name
with Y or Z

1) Definition
2) Implementation

Components :
* Attributes
* Methods
* Events
Attributes :
a) Instance attributes
DATA : <attributename> TYPE <data type>

b) Static attributes
CLASS-DATA : <attribute name> TYPE <datatype>
Method are defined in two ways
a) Instance methods
Methods : <method name> Importing <p>
exporting <p>
changing <p>
exceptions <e1> <e2>..
b) Static Methods
CLASS-METHODS <method name> Importing <p>
exporting <p>
changing <p>
exceptions <e1> <e2>..

Instance Attributes Static Attributes


Exist separately in each Available once for each
instance(object) of the class class
Attributes declared using Static attributes declared
DATA using CLASS-DATA
To access instance To access static attributes
attributes using -> operator using => operator
Instance attributes that Static attributes that have
have separate memory area same memory area for the
for separate instance all class instances (objects)
(object)

CLASS <class name> DEFINITION.


ENDCLASS.

CLASS <class name> Implementation.

ENDCLASS.
1) Declare a reference variable
DATA : <REFVAR> TYPE REF TO <CLASS/INTERFACE>.
2) Create an Object
CREATE OBJECT <REFVAR>.
3) Access attribute.
Instance attribute
<REFVAR>-><attribute>.
Static attribute
<REFVAR>-><attribute>
<CLASSNAME>=><attribute>
4) Access Method
Instance method
<REFVAR>-><method name>
Static method
<REFVAR>-><method name>
<CLASSNAME>=><method name>
* Method Declaration
CLASS CL_DEMO DEFINITION.
PUBLIC SECTION.
METHODS : <method name> importing <p1>....
exporting <p2>....
Changing <c1>.....
exceptions <e1>....
ENDCLASS.
* Method Implementation
CLASS CL_DEMO IMPLEMENTATION.
METHOD <method name>
<statements>
ENDMETHOD.

ENDCLASS.
* Static Method Declaration
CLASS CL_DEMO DEFINITION.
PUBLIC SECTION.
CLASS-METHODS : <method name> importing <p1>....
exporting <p2>....
Changing <c1>.....
exceptions <e1>....
ENDCLASS.
* Static Method Implementation
CLASS CL_DEMO IMPLEMENTATION.
METHOD <method name>
<statements>
ENDMETHOD.
ENDCLASS.

Instance Method Static Method


It will have import, export, It will same as instacne
changing and exceptions methods
parameters
Instance methods can Static methods can only
access/work with both work/access with static
static and instance attributes only.
attributes
Instance methods can call Static methods can call
using only object name using CLASS name with =>
with -> or object name with ->

Vous aimerez peut-être aussi