Sap Abap Oops: What Is OOP?
Sap Abap Oops: What Is OOP?
Sap Abap Oops: What Is OOP?
What is OOP?
Object Oriented programming breaks down tasks into objects that have data and function.This method
makes software programming understandable, flexible and reusable.Object-Oriented Programing (OOP)
was created with simplicity .It makes people communicate clearly, exchange information and ideas using
a common language .These objects are made up of their two main characteristics – properties (data) and
behaviour (or functions).
· Data abstraction
· Encapsulation
POP vs OOP
POP
· Emphasis:Emphasis is on tasks.
· Extensibility:This is more time consuming to modify and extend the existing functionality.
· Functions share global data and data cannot be hidden from each other
OOP
· OOP stands for Object-Oriented programming
· Modularization:Programs are organized into classes and objects and the functionalities are
embedded into methods of a class.
· Extensibility:New data and functions can be added effortlessly as and when required.
· Functions do not share global data – you can decide who can access your data
· It is very easy to extend functionality and add new data, by simply adding new objects.
OOP in ABAP
· However, as time progressed, they shifted it and transformed it into an OOP language Hence,
ABAP now follows the tenets of object orientation and paradigms like objects.
· As part of OOP, ABAP uses the concepts of inheritance, overloading, data hiding, etc. for better
functionality.
TERM MEANING
Class a complex collection of objects that mainly contain data fields and
Method behaviour of an object i.e. function modules that the object performs
· These characteristics and behaviour define the state of the object, and the actions that the
object will perform.
Objects can interact with one another by sending messages. Objects contain data and code to
manipulate the data. An object can also be used as a user-defined data type with the help of a class.
Objects are also called variables of the type class. After defining a class, you can create any number of
objects belonging to that class. Each object is associated with the data of the type class with which it has
been created.
Creating an Object
· Creating a reference variable with reference to the class. The syntax for which is −
· Creating an object from the reference variable. The syntax for which is −
· What this means is, we can define who all can have access to particular data of a class
1. Declaration
Syntax –
//define class
ENDCLASS.
Example –
//define class
ENDCLASS.
2. Definition
Syntax –
//define class
ENDCLASS.
Example –
//define class
ENDCLASS.
A class definition starts with the keyword CLASS followed by the class name, DEFINITION and the
class body. The definition of a class can contain various components of the class such as attributes,
methods, and events. When we declare a method in the class declaration, the method
implementation must be included in the class implementation.
· They can have any pre-defined data type like P, F, I ,C, N etc.
Instance: this includes the instance-specific state of object, the changes are different for all objects,
and this is declared by DATA statement
Static: this includes common state of the class to be shared by all instances of class, hence when we
change one state then all other objects can see the change, declared by CLASS-DATA statement
· Method definition may or may not contain parameters, which are passed when the method
is called
2. The access specifiers – public, private and protected – work the same way as they do for class
access specifiers
Static Attributes
A Static attribute is declared with the statement CLASS-DATA. All the objects or instances can use
the static attribute of the class. Static attributes are accessed directly with the help of class name
like class_name⇒name_1 = 'Some Text'.
· The program calls constructors automatically when an object of the class is created
· The constructor will trigger the operation included whenever an object is newly created in
execution
Report Name:ZR_SS_DATAFLAIR_SAMPLE_004
Output
· Whenever we redefine a variable within a method with a different value, that method will
use the redefined value of the variable
· However, if you want to access the originally declared value, then you can use the ME
operator
Report Name:ZR_SS_DATAFLAIR_SAMPLE_005
Output