Professional Documents
Culture Documents
?
Sl No Procedure Oriented
Object Oriented
1
Emphasis on doing things.
Emphasis on data rather than procedure.
2
Large programs are divided into smaller programs known as functions.
Programs are divided into objects.
3
Most of the functions share global data.
Data structures are desi
gned such that they characterized the objects.
4
Data move openly around the system from function to function. Function
s that operate on the data of an object are tied together in the data structure.
Data is hidden and cannot be accessed by external functions.
5
Top-down approach.
Bottom-up approach.
6
In general:
1)functions
2)modules
3)call
4)variable
1) methods
2)objects
3)message
4)attribute
What are the advantages of ABAP OOPS?
1.
Through inheritance we can eliminate redundant code and extend the use o
f existing class.
2.
We can develop programs from the existing classes given by SAP.
3.
The concept of data hiding helps the programmer to build secure programs
that cannot be invaded by code in other parts of programs.
4.
OOP system can be easily upgraded from smaller system to larger system.
5.
Software complexity can be easily managed.
6.
Code reusability.
7.
For interfacing ABAP with Microsoft technologies, Java as all these are
Build on the concept of OOP .
8.
To easily understand the recent concepts of ABAP ex BAPI, BADI workflow.
What are the core ABAP oops concepts?
Inheritance: Inheritance is the ability of an object to inherit the properties a
nd methods of another object. This characteristic leads to the creation of famil
ies of objects (just like families exist for humans) with parent objects and chi
ld objects.
Polymorphism: Polymorphism is about an objects ability to provide context when m
ethods or operators are called on the object.
Definition: Polymorphism
In object-oriented programming, polymorphism (from the Greek meaning "having mul
tiple forms") is the characteristic of being able to assign a different meaning
to a particular symbol or "operator" in different contexts. The simple example i
s two classes that inherit from a common parent and implement the same virtual
method.
Encapsulation: Encapsulation is the ability that an object has to contain and re
strict the access to its members. Encapsulation is a key concept of object progr
amming that ensures the autonomy and integrity of the objects.
Abstraction: Another OOP concept related to encapsulation that is less widely us
ed but gaining ground is abstration.
Definition: Abstraction
Through the process of abstraction, a programmer hides all but the relevant data
about an object in order to reduce complexity and increase efficiency. In the s
ame way that abstraction sometimes works in art, the object that remains is a re
presentation of the original, with unwanted detail omitted. The resulting object
itself can be referred to as an abstraction, meaning a named entity made up of
equent coding that is not itself part of a processing block is therefore not acc
essible.
rt of a processing block is therefore not accessible.
What is a reference variable?
Objects can only be created and addressed using reference variables. Reference v
ariables allow you to create and address objects. Reference variables can be def
ined in classes, allowing you to access objects from within a class.
Ex.
...
CLASS lcl_vehicle DEFINITION.
PUBLIC SECTION.
PRIVATE SECTION.
ENDCLASS.
CLASS lcl_vehicle IMPLEMENTATION.
ENDCLASS.
DATA: r_vehicle1 TYPE REF TO lcl_vehicle,
r_vehicle2 TYPE REF TO lcl_vehilce.
START-OF_SELECTION.
rt of a processing block is therefore not accessible.
What is a reference variable?
Objects can only be created and addressed using reference variables. Reference v
ariables allow you to create and address objects. Reference variables can be def
ined in classes, allowing you to access objects from within a class.
Ex.
...
CLASS lcl_vehicle DEFINITION.
PUBLIC SECTION.
PRIVATE SECTION.
ENDCLASS.
CLASS lcl_vehicle IMPLEMENTATION.
ENDCLASS.
DATA: r_vehicle1 TYPE REF TO lcl_vehicle,
r_vehicle2 TYPE REF TO lcl_vehilce.
START-OF_SELECTION.
What are Abstract classes and an Abstract Method?
Abstract classes themselves cannot be instantiated (although their subclasses ca
n) References to abstract classes can refer to instances of subclasses. Abstract
(instance) methods are defined in the class, but not implemented. They must be
redefined in subclasses.
Abstract instance methods are used to specify particular interfaces for subclass
es, without having to immediately provide implementation for them. Abstract meth
ods need to be redefined and thereby implemented in the subclass (here you also
need to include the corresponding redefinition statement in the DEFINITION part
of the subclass).
Classes with at least one abstract method are themselves abstract.
Static methods and constructors cannot be abstract (they cannot be redefined).
Abstract method
Abstract instance methods are used to specify particular interfaces for subclass
es, without having to immediately provide implementation for them. Abstract meth
ods need to be redefined and thereby implemented in the subclass (here you also
need to include the corresponding redefinition statement in the DEFINITION part
of the subclass). Classes with at least one abstract method are themselves abstr
act. Static methods and constructors cannot be abstract (they cannot be redefine
d).
A component instance is a running component that can be run in parallel with oth
er instances of the same component.
How is Encapsulation implemented in OOPs?
Encapsulation means that the implementation of an object is hidden from other co
mponents in the system, so that they cannot make assumptions about the internal
status of the object and therefore dependencies on specific implementations do n
ot arise.
What are interfaces? What are the advantages of interfaces?
Interfaces are the means of choice for describing external points of contact or
protocols, without linking them to a type of implementation. An extra layer is i
ntroduced between the client and the server to protect the client explicitly fro
m the server, thereby making the client independent. Interfaces enable you to wo
rk uniformly with different classes (providers/servers). In particular, they alw
ays ensure polymorphic behavior as they do not have their own implementation, bu
t instead allow the providers to carry it out. The definition of an interface is
always an abstraction: The user wants to handle various providers in the same w
ay and must therefore abstract concrete implementations to a description of the
services required to fulfill the task. You can also use interfaces to achieve mu
ltiple inheritance by defining the functionality to be inherited by a second cla
ss as an interface that the inheriting class then has to implement.
INTERFACE lif_partners.
METHODS: display_partner.
ENDINTERFACE.
CLASS lcl_rental DEFINITION.
PUBLIC SECTION.
INTERFACES lif_partners.
ENDCLASS.
CLASS lcl_rental IMPLEMENTATION.
METHOD lif_partners~display_partner.
* just call existing method that fits
display_attributes( ).
...
ENDMETHOD.
ENDCLASS.
What are BADIs? What are BADI filters?
BADI Business Add Ins are enhancements to the standard version of the code of SA
P.
Filter Badi- Business Add-Ins may be implemented on the basis of a filter value.
If an enhancement for country-specific versions is provided for in the standard
version, it is likely that different partners will want to implement this enhan
cement. The individual countries can create and activate their own implementatio
n.
How can an event be raised and handled?
Events link objects or classes more loosely than direct method calls do. Method
calls establish precisely when and in which statement sequence the method is cal
led. However, with events, the reaction of the object to the event is triggered
by the event itself. Events are most often used in GUI implementations. At the m
oment of implementation, a class defines its:
Instance events (using the EVENTS statement)
Static events (using the CLASS-EVENTS statement)
Classes or their instances that receive a message when an event is triggered at
runtime and want to react to this event define event handler methods.
Statement:
[CLASS-]METHODS <handler_method> FOR EVENT <event> OF <classname>.
These classes or their instances are registered to one or more events
at runtime.
Statement: SET HANDLER <handler_method> FOR <reference>. (for instance events)
SET HANDLER <handler_method>. (for static events)
A class or instance can trigger an event at runtime using the RAISE EVENT statem
ent.
EXCEPTIONS <exception>
RAISING <class_exception> ].
ENDCLASS.(signature of a method).
CLASS <classname> IMPLEMENTATION.
METHOD <method_name>.
...
ENDMETHOD.
ENDCLASS.
Syntax to find out if a reference variable is referring to an object?
CLASS lcl_vehicle DEFINITION.
PUBLIC SECTION.
...
PRIVATE SECTION.
...
ENDCLASS.
CLASS lcl_vehicle IMPLEMENTATION.
...
ENDCLASS.
DATA: r_vehicle1 TYPE REF TO lcl_vehicle,
r_vehicle2 TYPE REF TO lcl_vehilce.
START-OF_SELECTION.
. . . . . . . . . . . . . .
Explain syntax Definition Load .
CLASS CL_GUI_CFW DEFINITION LOAD.
To access the static methods of a class we define it with LOAD.
As in BADI we use the static methods of the Class which is been used in the BADI
.
so we define the class using the kewowrd LOAD.
DEFERRED
CLASS lcl_event_receiver DEFINITION DEFERRED.
1. It means "load all the definition of the class lcl_event_receiver". After thi
s statement, you can then access methods and attributes of lcl_event_receiver, e
ven though it may be defined considerably later in the class.
2. Definition deferred means that you can refer to objects in your program which
haven't yet been defined but will be later on in your code. You could have two
classes in an abap say and data elements / types in the first class refer to the
2nd class such as obj1 type ref to zclass2 definition deferred. The zclass2 def
inition will appear later in your abap.
3. If you don't put definition deferred then when you check the program it will
give a syntax error of zclass2 not found.
DELEGATION
In delegation, two objects are involved in handling a request: The recipient of
the request delegates the execution of the request to a delegate.
What is an alias in ABAP OOPS?
Within a class, attribute names, method names, event names, constant names, type
names and alias names all share the same namespace. In ABAP Objects, the same c
omponents can be defined in interfaces and in classes. This allows you to shift
part of the public point of contact of a class into an interface, even though th
e class is already in use; users will not notice the difference as long as you u
se alias names (see appendix) for the components that are now in the interface.
To simplify accessing interface methods you can work with alias names.
1. Alias names can only appear in the in the declaration part of a class or in t
he interface definition.
Example for an alias in the interface: ALIASES a1 FOR lif_interface~method1
2. An alias defined in this way can be directly addressed using r_ref->a1.
What is a Persistent Class? Explain.
To use the Persistence Service for objects, the classes of these objects must be
created as persistent classes in the Class Builder. The term persistent class d
oes not imply that a class is persistent. (As a template for objects, every clas
s is persistent). Rather, it means that the objects of that class and their stat
e are managed by the Persistence Service. For example, the objects of these clas
ses are instantiated in the ABAP program with a method of the Persistence Servic
e, which ensures that the initialization is correct (not with the usual CREATE O
BJECT statement). When the Class Builder creates a persistent class, it automati
cally generates an associated class, known as the class actor or class agent, wh
ose methods manage the objects of persistent classes. As well as their identity,
persistent classes can contain key attributes, which allow the Persistence Serv
ice to ensure that the content of each persistent object is unique.
What is a functional Method?
Methods that have a RETURNING parameter are described as functional methods. The
se methods cannot have EXPORTING or CHANGING parameters, but has many (or as few
) IMPORTING parameters and exceptions as required.
Functional methods can be used directly in various expressions:
1.
Logical expressions (IF, ELSEIF, WHILE, CHECK, WAIT)
2.
The CASE statement (CASE, WHEN)
3.
The LOOP statement
4.
Arithmetic expressions (COMPUTE)
5.
Bit expressions (COMPUTE)
6.
The MOVE statement.
Functional Method Example.
CLASS lcl_vehicle DEFINITION.
PUBLIC SECTION.
METHODS: get_average_fuel
IMPORTING im_distance TYPE s_distance,
im_fuel TYPE ty_fuel
RETURNING VALUE(re_fuel) TYPE ty_fuel,
ENDCLASS.
DATA: r_vehicle1 TYPE REF TO lcl_vehicle,
r_vehicle2 TYPE REF TO lcl_vehicle,
avg_fuel TYPE ty_fuel.
...
* example for short syntax in aritmet. operation
avg_fuel =
r_vehicle1->get_average_fuel( im_distance = 500 im_fuel = 50 )
+ r_vehicle2->get_average_fuel( im_distance = 600 im_fuel = 60 ).
What is a de-referenced variable? What is a garbage collector?
To go to an address before performing the operation a dereferenced variable is a
pointer to the variable, not the variable itself. A pointer can be re-assigned
any number of times while a reference cannot be reassigned after initialization.
Field symbols are similar to dereferenced pointers. Thus, you can only access t
he content of the data object to which the field symbol points. (That is, field
symbols use value semantics). If you want to access the content of the data obje
ct, you need to dereference the data reference first.
Example.
As soon as no more references point to an object, the Garbage Collector removes
it from the memory. The Garbage Collector is a system routine that automatically
deletes objects that can no longer be addressed from the main memory and releas
es the memory space they occupied.
Procedure how garbage collector works..
Independent references are references that have not been defined within a class.
What is a Framework?
Automation Controller
The automation controller is the central instance at the frontend. It administer
s all instances of custom controls.
The Automation Controller also contains a list of the events that a custom contr
ol can trigger. All communication between the controls at the frontend and the a
pplication program at the backend runs through the Automation Controller.
ABAP Objects Control Framework
The ABAP Objects Control Framework has a similar function at the backend to that
of the
Automation Controller at the frontend. All method calls from an application prog
ram to a custom control run through the Control Framework. In order to avoid eac
h method call establishing a separate connection to the frontend, the method cal
ls are buffered in the automation queue. The automation queue is not sent to the
frontend until you reach a synchronization point. Like the Automation Controlle
r, the Control Framework has a list of control events. This list also contains t
he corresponding handler methods that need to be called when the event occurs. T
he Control Framework also maintains a list of the control instances you have cre
ated. This list is the basis for the lifetime management of controls.
What is a Static Constructor? What are the advantages?
1.
The static constructor is a special static method in a class with the na
me class_constructor.
2.
It is executed precisely once per program.
3.
The static constructor of a class <classname> is called automatically wh
en the class is first accessed, but before any of the following actions are exec
uted:
4.
Creating an instance in the class using CREATE OBJECT <obj>, where <obj>
has the data type REF TO <classname>
5.
Addressing a static attribute using <classname>=><attribute>
6.
Calling a static attribute using CALL METHOD <classname>=><classmethod>
7.
Registering a static event handler method using SET HANDLER
<classname>=><handler_method> FOR <obj>
8. Registering an event handler method for a static event in class <classname>.
9. The static constructor cannot be called explicitly.
Advantages:
1.
For static constructors, unlike instance constructors, the static constr
uctor in the superclass is called automatically, that is the runtime system auto
matically ensures that the static constructors of all its superclasses have alre
ady been executed before the static constructor in a particular class is execute
d.
2.
For static constructors, unlike instance constructors, the static constr
uctor in the superclass is called automatically, that is the runtime system auto
matically ensures that the static constructors of all its superclasses have alre
ady been executed before the static constructor in a particular class is execute
d.
3.
the static constructor of the class creates exactly one instance of this
class, which points to the attribute . This object is part of the persistence s
ervice and its methods are used to manage the object of the persistent class.
What is Private Constructor? Limitations?
Private constructors are used to restrict the instantiation of object using 'new
' operator. This type of constructors are mainly used for creating singleton obj
ect.
Limitations:
1.
A private constructor is a special instance constructor. It is commonly
used in classes that contain static members only.
2.
If a class has one or more private constructors and no public constructo
rs, then other classes (except nested classes) are not allowed to create instanc
es of this class.
3.
An instance constructor will always run after a static constructor.
4.
Private constructors prevent a class from being explicitly instantiated
by callers.
Can a class be defined without a constructor?
Yes, class can be created without any constructor. Default constructor will be c
reated when we define a class without constructor.