Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
1
Topics to be covered on Day 2
2
ABAP
3
Concepts of OOP
Abstraction
- Ability to reflect real-world processes
- real-world modeled in classes and mapped in objects
Encapsulation
- Implementation details are hidden behind interfaces.
- Ensure that the abstract representation of an object is used only in accordance
with its specification.
Inheritance
- Abstractions derived from existing ones.
Instantiation
- Enables you to create multiple instances of a class.
4
OOP ABAP
5
Keywords and Syntax
6
Class Definition & Implementation
ENDCLASS.
CLASS class_name IMPLEMENTATION.
....
ENDCLASS.
7
Components of Class
Attributes
- The data objects within a class
- All data types of the ABAP type hierarchy can be used
- DATA statement is used for instance attributes
- CLASS-DATA for static attribute
Methods
- Processing block with a parameter interface
- Local data
- Instance method can access all attributes and
events
- Static method can access only static attributes and events
Events
Allow the objects of a class to publish its status. Other objects can then respond to the change in status.
1. Event trigger does not know the event handler.
2. Event trigger therefore does not initially know if the event will even have an effect.
8
Visibility Section
Public
- All components are public and can be addressed by all
subclasses, the class itself and other external classes.
Protected
- Components of this section are protected and can only be
addressed by the class itself and the subclasses
Private
- Can only be used in the methods of the class itself
9
Define Attribute
10
Define Instance Method
CLASS class_name DEFINITION.
PUBIC SECTION.
CLASS-METHODS meth
IMPORTING .. Ii TYPE type
EXPORTING .. Ei TYPE type ..
CHANGING .. Ci TYPE type ..
EXCETPIONS .. Ei
ENDCLASS.
11
Components Methods
class constructor
First time a class is accessed
ABAP Objects does not provide any destructors for application development.
12
Functional Method
Functional method
Method with any number of input parameters but only one return value.
It can be used in operand positions for functions and expressions.
Syntax
IF obj->functional_method( ) = abap_true.
do some thing
ENDIF.
13
Event
Each method can trigger the events of its class
Methods can be declared as handler methods for events
14
Event Handler class
CLASS handler_class DEFINITION.
PUBLIC SECTION.
METHODS: handler_method FOR EVENT
raised_event OF raising_class.
ENDCLASS.
SET HANDLER
handler_instance->handler_method
FOR ALL INSTANCES.
15
Define Object Reference Variables
16
Method Call
Call instance method:
Syntax:
CALL METHOD oref->get_data.
17
Exception Handling
Exceptions are events that arise during the execution of an ABAP program
at which the program is interrupted, because it is not possible to
continue processing the program in a meaningful way.
18
Inheritence
Re-implement the method of supper class
19
Final Class
When needed to protect a class or individual method from uncontrolled specialization
Syntax:
CLASS class DEFINITION FINAL.
ENDCLASS
Final Method
Syntax:
CLASS class DEFINITION FINAL.
PUBLIC SECTION.
METHODS: method FINAL.
ENDCLASS
20
Interface & Abstract class
What is an interface ?
It is an entity just like a class but interface cant have implementation
INTERFACE zif_order.
METHODS: set_order_data IMPORTING iv_order_Data TYPE STRING.
METHODS: create_order.
ENDINTERFACE.
*
CLASS zcl_sales_order DEFINITION.
PUBLIC SECTION.
INTERFACES: zif_order.
ENDCLASS.
21
Interface & Abstract class
22
Interface & Abstract class
Differences !!
Multiple Inheritance
Adding new method
Default behavior
Visibility
23
Casting
Types:
Narrowing cast
Widening Cast
24
Narrowing Cast
Narrowing cast:
Declare a variable with reference to the super class.
DATA: REF_VEHICLE TYPE REF TO VEHICLE.
REF_VEHICLE = REF_TRUCK.
25
Widening Cast
When we assign the instance of the Super class to the Subclass, than it is
called the Widening Cast, because we are moving to the More Specific View
from the Less specific view.
Special assignment with the casting operator ?=
Widening cast:
REF_TRUCK ?= REF_VEHICLE .
26