Documente Academic
Documente Profesional
Documente Cultură
Sl No
Procedure Oriented
Object Oriented
Data structures are designed such that they characterized the objects.
Functions 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.
Top-down approach.
In general:
Bottom-up approach.
1)functions
1) methods
2)modules
2)objects
3)call
3)message
4)variable
4)attribute
1.
Through inheritance we can eliminate redundant code and extend the use of existing class.
2.
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.
6.
Code reusability.
7.
For interfacing ABAP with Microsoft technologies, Java as all these are Build on the concept of OOP .
8.
Inheritance: Inheritance is the ability of an object to inherit the properties and methods of another object. This characteristic leads to the creation of families of objects (just like
families exist for humans) with parent objects and child objects.
Polymorphism: Polymorphism is about an objects ability to provide context when methods or operators are called on the object.
Definition: Polymorphism
In object-oriented programming, polymorphism (from the Greek meaning "having multiple forms") is the characteristic of being able to assign a different meaning to a particular
symbol or "operator" in different contexts. The simple example is 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 restrict the access to its members. Encapsulation is a key concept of object programming that
ensures the autonomy and integrity of the objects.
Abstraction: Another OOP concept related to encapsulation that is less widely used 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 same way that
abstraction sometimes works in art, the object that remains is a representation 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 selected attributes and behavior specific to a particular usage of the originating entity.
What is UML?
UML (Unified Modeling Language) is a standardized modeling language. It is used for the specification, construction, visualization and documentation of models for software
systems and enables uniform communication between various users.
UML does not describe the steps in the object-oriented development process.
SAP uses UML as the company-wide standard for object-oriented modeling.
UML describes a number of different diagram types in order to represent different views of a system.
In general there are two types of Objects: Instance Object and Static Object and as such there are two types of Classes: Instance class and Static Class.
Specifically when it comes to visibility, Private class, Protected class and Public classes are the types of classes one can have.
We can create four types of classes under final and only modeled category(optional) with the private, protected, public and abstract instantiation.
Usual Abap Class.
Exception Class(With/Without messages).
Persistent Class.
Test Class(ABAP Unit).
Objects can only be created and addressed using reference variables. Reference variables allow you to create and address objects. Reference variables can be defined 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.
Objects can only be created and addressed using reference variables. Reference variables allow you to create and address objects. Reference variables can be defined 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.
Abstract classes themselves cannot be instantiated (although their subclasses can) 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 subclasses, without having to immediately provide implementation for them. Abstract methods 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 subclasses, without having to immediately provide implementation for them. Abstract methods 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 subclasses, without having to immediately provide implementation for them. Abstract methods 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 (instance) methods are defined in the class, but not implemented
They must be redefined in subclasses.
CLASS lcl_vehicle DEFINITION ABSTRACT.
PUBLIC SECTION.
METHODS estimate_fuel_consumption ABSTRACT
IMPORTING ...
ENDCLASS.
Final method
Final classes cannot have subclasses.
Final methods cannot be redefined in subclasses.
A final class implicitly only contains final methods. In this case, you cannot enter FINAL explicitly for these methods. Methods cannot be both final and abstract. Classes, on the
other hand, that are both abstract and final can be useful: Only static components can be used.
A superclass is a generalization of its subclasses. The subclass in turn is a specialization of its superclasses.
CLASS lcl_vehicle DEFINITION.
PUBLIC SECTION.
METHODS estimate_fuel
IMPORTING im_distance TYPE ty_distance
RETURNING VALUE(re_fuel) TYPE ty_fuel.
ENDCLASS.
CLASS lcl_truck DEFINITION INHERITING FROM lcl_vehicle.
PUBLIC SECTION.
METHODS estimate_fuel REDEFINITION.
ENDCLASS.
CLASS lcl_truck IMPLEMENTATION.
METHOD estimate_fuel.
super->estimate_fuel(...)
ENDMETHOD.
ENDCLASS.
The assignment of a subclass instance to a reference variable of the type "reference to superclass" is described as a narrowing cast, because you are switching from a more
detailed view to a one with less detail.
It can be implemented as follows.
After the narrowing cast, you can use the r_vehicle reference to access the components of the truck instance that were inherited from lcl_vehicle - obviously, in some cases with
the limitations entailed by their visibility. You can no longer access the truck-specific part of the instance (get_cargo in the above example) using the r_vehicle reference.
DATA: r_vehicle TYPE REF TO lcl_vehicle,
r_truck TYPE REF TO lcl_truck.
CREATE OBJECT r_truck.
* Narrowing Cast
r_vehicle = r_truck
Principle of Narrowing Cast
_r_truck_
_r_vehicle_
The widening cast is, as with inheritance, the opposite of the narrowing cast: Here it is used to retrieve a class reference from an interface reference.
METHOD get_max_cargo.
DATA: r_vehicle TYPE REF TO lcl_vehicle,
r_truck TYPE REF TO lcl_truck.
LOOP AT vehicle_list INTO r_vehicle.
TRY.
r_truck ?= r_vehicle.
* put max cargo in variable re_cargo...
CATCH cx_sy_move_cast_error.
* react on that cast error
ENDTRY.
ENDLOOP.
What is a singleton?
If it is to be impossible to instantiate a class more than once (for example, because it serves as a data administrator or data container), you can use the singleton concept. The
class is defined with the addition CREATE PRIVATE and FINAL and instantiated using its static constructor. A public static component could then make the reference to the
class available to an external user.
DATA: r_single type ref to cl_singleton.
START-OF-SELECTION.
r_single = cl_singleton=>get_singleton( ).
What is a constructor?
Special method for creating objects with defined initial state, Only has IMPORTING,
parameters and EXCEPTIONS, Is executed only once per instance.
Example of Constructor
CLASS my_class DEFINITION.
PUBLIC SECTION.
METHODS CONSTRUCTOR. note constructor should be always declared in public.
ENDCLASS.
CLASS my_class IMPLEMENTATION.
METHODS CONSTRUCTOR.
write :/ this is constructor method.
ENDMETHOD.
ENDCLASS.
Inherited methods can be redefined in subclasses Redefined methods must be re-implemented in subclasses. The signature of redefined methods cannot be changed Static
methods cannot be redefined. In inheritance, static components are "shared": A class shares its non-private static attributes with all its subclasses. In ABAP Objects, you can
not only add new components, but also provide inherited methods with new implementations. This is known as redefinition. You can only redefine (public and protected)
instance methods, other components (static methods, attributes and so on) cannot be redefined. Changes to method parameters (signature changes) are not possible..
In inheritance, static components are "shared": A class shares its non-private static attributes with all its subclasses. => and -> are the component selectors used to refer.
A component instance is a running component that can be run in parallel with other instances of the same component.
Encapsulation means that the implementation of an object is hidden from other components in the system, so that they cannot make assumptions about the internal status of
the object and therefore dependencies on specific implementations do not arise.
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 introduced between
the client and the server to protect the client explicitly from the server, thereby making the client independent. Interfaces enable you to work uniformly with different classes
(providers/servers). In particular, they always ensure polymorphic behavior as they do not have their own implementation, but 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 way and must therefore abstract concrete implementations to a
description of the services required to fulfill the task. You can also use interfaces to achieve multiple inheritance by defining the functionality to be inherited by a second class 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.
BADI Business Add Ins are enhancements to the standard version of the code of SAP.
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 enhancement. The individual countries can create and activate their own implementation.
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 called. 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 moment of implementation, a class
defines its:
runtime.
1.
Exceptions that occur in procedures (methods, function modules, or subroutines) do not necessarily need to be handled there; they can be passed along to the calling program.
2.
The calling program can then handle the exception itself or also pass it along to its own caller, and so on.
3.
The highest levels to which an exception can be passed are processing blocks without local data areas - that is, event blocks or dialog modules.
4.
The exceptions passed along by the called procedures must be dealt with there, as must any exceptions raised within this processing block itself. Otherwise a runtime error
occurs.
5.
To pass along an exception from a procedure, you generally use the RAISING addition when defining the procedure interface. In methods of local classes and subroutines,
specify the RAISING addition directly when defining the procedure
the exception we have defined (zcx_wrong_planetype) is raised if the airplane type passed to the method get_technical_attributes is not stored in the table saplane.
Here, however, the exception is only raised in the method get_technical_attributes, not handled there.
To pass the exception along to the caller of the method, we enter it after the RAISING keyword.
Now, the caller - that is, the method display_attributes - handles the exception. For this purpose, we have implemented a TRY-ENDTRY control structure in this method. The
methodget_technical_attributes is now called in the TRY block of this control structure.
If the exception is raised in the method get_technical_attributes, the program continues by handling this exception. That is, the method get_technical_attributes is terminated
and the appropriate CATCH block is processed within the caller. Note in particular that the program no longer executes the WRITE statements entered in the TRY
block afterget_technical_attributes is called.
a. Global
b. Local Exceptions Class.
Protected components Only visible within the class and its sub classes.
Methods have a parameter interface (called signature ) that enables them to receive values when they are called and pass values back to the calling program.
In ABAP Objects, methods can have IMPORTING, EXPORTING, CHANGING, and RETURNING parameters as well as exception parameters.
CLASS <classname> DEFINITION.
...
METHODS: <method_name>
[ IMPORTING <im_var> TYPE <type>
EXPORTING <ex_var> TYPE <type>
CHANGING <ch_var> TYPE <type>
RETURNING VALUE(<re_var>) TYPE <type>
EXCEPTIONS <exception>
RAISING <class_exception> ].
ENDCLASS.(signature of a method).
DEFERRED
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.
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
components 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 the class is already in
use; users will not notice the difference as long as you use 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 the 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.
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 does not imply
that a class is persistent. (As a template for objects, every class is persistent). Rather, it means that the objects of that class and their state are managed by the Persistence
Service. For example, the objects of these classes are instantiated in the ABAP program with a method of the Persistence Service, which ensures that the initialization is correct
(not with the usual CREATE OBJECT statement). When the Class Builder creates a persistent class, it automatically generates an associated class, known as the class
actor or class agent, whose methods manage the objects of persistent classes. As well as their identity, persistent classes can contain key attributes, which allow the
Persistence Service to ensure that the content of each persistent object is unique.
Methods that have a RETURNING parameter are described as functional methods. These 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.
2.
3.
4.
5.
6.
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 the 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 object, 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 releases 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 administers all instances of custom controls.
The Automation Controller also contains a list of the events that a custom control can trigger. All communication between the controls at the frontend and the application
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 program to a custom control run through the Control Framework. In order to avoid each method call
establishing a separate connection to the frontend, the method calls are buffered in the automation queue. The automation queue is not sent to the frontend until you reach a
synchronization point. Like the Automation Controller, the Control Framework has a list of control events. This list also contains the corresponding handler methods that need to
be called when the event occurs. The Control Framework also maintains a list of the control instances you have created. This list is the basis for the lifetime management of
controls.
1.
The static constructor is a special static method in a class with the name class_constructor.
2.
3.
The static constructor of a class <classname> is called automatically when the class is first accessed, but before any of the following actions are executed:
4.
Creating an instance in the class using CREATE OBJECT <obj>, where <obj> has the data type REF TO <classname>
5.
6.
7.
1.
For static constructors, unlike instance constructors, the static constructor in the superclass is called automatically, that is the runtime system automatically ensures that the
static constructors of all its superclasses have already been executed before the static constructor in a particular class is executed.
2.
For static constructors, unlike instance constructors, the static constructor in the superclass is called automatically, that is the runtime system automatically ensures that the
static constructors of all its superclasses have already been executed before the static constructor in a particular class is executed.
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 service and its methods are used
to manage the object of the persistent class.
Private constructors are used to restrict the instantiation of object using 'new' operator. This type of constructors are mainly used for creating singleton object.
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 constructors, then other classes (except nested classes) are not allowed to create instances of this class.
3.
4.
Yes, class can be created without any constructor. Default constructor will be created when we define a class without constructor.
A class can provide friendship to other classes and interfaces (and hence all classes that Implement the interface).
To do this you use the FRIENDS additions to the CLASS statement, in which all classes and interfaces that are to be provided friendship are listed.
Friends are allowed to access the protected and private components of the class providing the friendship and can always create instances of this class, regardless of the
CREATE addition to the CLASS statement.
In principle, providing friendship is one-sided: A class providing friendship is not automatically a friend of its friends. If a class providing friendship wants to access the non-public
components of a friend, this friend has to explicitly provide friendship to it.
Classes that inherit from friends and interfaces that contain a friend as a component interface also become friends. Therefore, extreme caution is advised when providing
friendship. The higher up a friend is in the inheritance tree, the more subclasses can access all components of a class providing friendship. However, providing friendship, unlike
the attribute of being a friend, is not inherited.
A friend of a superclass is therefore not automatically a friend of its sub classes.
RTTS (RunTime Type Services) allows to get the definition of variables or to create them during program execution. RTTS is made of 2 components:
1.
RTTI (RunTime Type Identification) is used to get the definition of existing variables or existing types
2.
RTTC (RunTime Type Creation) is used to create new variables with any definition; they must be followed by the ABAP statement CREATE DATA ... TYPE HANDLE ... to
create the variable.
Yes.
Local classes are only visible in the program they were defined in.
No global access possible.
Not stored in the Repository, no where-used list, and so on.
Local classes and interfaces are only known within the program in which they are defined and implemented.
Local classes and interfaces are not stored in the Repository (no TADIR entry). There is no "global" access to these classes or interfaces (for example, from other programs).
What is MVC?
Model View Controller, is widely used in the user interface programming field and which has proved its worth, as an extension of the previous BSP implementation model. Its
controller-based use ensures an even clearer distinction between application logic and presentation logic in BSP applications. You can structure graphical user interfaces clearly
and organize them in logical units, even with complex applications.
Using the MVC design pattern has the following advantages:
Structuring BSP applications is simplified, since the view is cleanly separated from the controller and the model. This not only facilitates changing BSP applications, but
You have the option of generating program-driven layout. The HTML/XML output is therefore created by program code instead of a page with scripting.
Navigation using the <bsp:goto> element and call using the <bsp:call> element. The advantage of using <bsp:goto> navigation over redirect is that there is no additional
network traffic. Furthermore, you remain in the same work process, which can have advantages for creating objects and memory space. The call using <bsp:call> element is
more variable than adding them using INCLUDE directive, since it is triggered at runtime.
With the call option using <bsp:call>, you can also distribute the user interface into components.