Vous êtes sur la page 1sur 8

OO ABAP Elements

CLASSES, ATTRIBUTES & METHODS


Classes, Attributes & Methods

The concept of classes is the foundation for all object-oriented thinking.

A class is a set of objects that have the same structure and the same
behavior.

We will start with a simple demonstration, lets create a class for our
previous function group example, we will call it ZCL_VEHICLE.

Our class will have the following components:


ZCL_VEHICLE: Class Components

Private Public
Components Components

Speed Increase_speed
Private Access, Public Access,
generally: generally:
Attributes Methods
Data Types Attributes can be Decrease_speed Events
one of three types:
Elementary
Structured
Table Type Get_speed
TO CREATE AN ABAP CLASS,
Practical OPEN TRANSACTION CODE
SE24.
Example
Attributes: Visibility & Level

Visibility Level
Public Attributes:
Instance Attributes:
Generally Visible
Exist per instance
Generally changeable. Exception:
Defined with DATA
READ-ONLY addition.

Private Attributes Static Attributes:


Exist per class
Only visible within the class
Definition with CLASS-DATA
Only changeable within the class

Lets go back to SE24 and create more attributes


Methods: Visibility & Level

Visibility Level
Public Methods: Instance Methods:
Can generally be called Access to static and instance
components is possible
Defined with METHODS
Private Methods:
Can only be called within the class
Static Methods:
Only access to static components is
possible
Defined with CLASS-METHODS
You can access public
attributes and methods from
Access to Static outside a class (e.g. from a
main program)
and Instance
Static attributes are
Elements accessed using:
classname=>static_attribute.
ATTRIBUTES AND METHODS
Instance attributes are
accessed with :
ref->instance_attribute.
Practical LETS CREATE A PROGRAM
THAT USES CLASS:
Example ZCL_VEHICLE

Vous aimerez peut-être aussi