Professional Documents
Culture Documents
OOABAP - Overview PDF
OOABAP - Overview PDF
OOABAP
OBJECTIVE
• OO concepts
• Overview of OOABAP
OO - CONCEPTS
• Object
• Class
• Attributes
• Encapsulation
• Polymorphism
• Inheritance
OOABAP - Attributes
Public
Private
Attributes
Instance
Static
OOABAP- Methods
Public
Private
Methods
Constructor
Static Constructor
CLASSES – DEFINITION SYNTAX
CLASS xxx DEFINITION.
*Public Section
PUBLIC SECTION.
TYPES:
DATA:
*Static data
CLASS-DATA:
*Methods
METHODS:
*Using the constructor to initialize parameters
constructor IMPORTING xxx type yyy,
*Method with parameters
mm1 IMPORTING iii TYPE ttt.
*Method without parameters
mm2.
*Static methods
CLASS-METHODS:
*Protected Section
*Private Section
END CLASS
CLASSES –IMPLEMENTATION SYNTAX
CLASS lcl_airplane
IMPLEMENTATION.
METHOD constructor.
ENDMETHOD.
METHOD mm1.
ENDMETHOD.
METHOD mm2.
ENDMETHOD.
ENDCLASS.
CLASSES
• This example shows how to create a simple employee class. The
constructor method is used to initialize number and name of the
employee when the object is created. A display_employee method can
be called to show the attributes of the employee, and CLASS-METHOD
display_no_of_employees can be called to show the total number of
employees (Number of instances of the employee class).
SUB CLASSES
Declaration
Definition:
• Declaration (No visibility sections)
• Components (Attributes, methods, constants, types) defined similar to
classes
• Defined in public section of class definition
INTERFACES – DEFINITION SYNTAX
Definition INTERFACE lif_document
DATA: author type ref to lcl_author.
METHODS: print,
display.
ENDINTERFACE.
CLASS lcl_text_document DEFINITION.
PUBLIC SECTION.
INTERFACES lif_document.
METHODS display.
ENDCLASS.
Implementation CLASS lcl_text_document IMPLEMENTTION.
METHOD lif_document~print.
ENDMETHOD.
METHOD lif_document~display
ENDMETHOD.
METHOD display.
ENDMETHOD.
ENDCLASS.
REPORT zzz.
DATA: text_doc TYPE REF TO lcl_document.
Start-of-selection.
CREATE OBJECT text_doc.
CALL METHOD text_doc->lif_document~print.
INTERFACES
This example is similar to the previous example, however an interface
is implemented with the method add_employee. Note that the interface
is only implemented in the super class ( The INTERFACE statement),
but also used in the subclasses.
When an event is triggered, only those events handlers that have registered
themselves using SET HANDLER by this point of runtime are executed.
You can register an event using ACTIVATION 'X' and deregister it by using
ACTIVATION 'SPACE‘
EVENTS – DEFINTION SYNTAX
Definition
CLASS <classname> DEFINITION.
EVENTS: <event> EXPORTING VALUE (<ex_par>) TYPE type.
Implementation
CLASS <classname> IMPLEMENTATION.
METHOD <m>:
RAISE EVENT <event> EXPORTING <ex_par> = <act_par>.
Handling events:
CLASS <classname> DEFINITION.
METHODS: <on_event> FOR <event> OF <classname> ! <interface> IMPORTING
<imp_par1>...<imp_parN> SENDER.
Setting handler
SET HANDLER <ref_handle> <on_event> FOR <ref_sender> ! FOR ALL
INSTANCES
[ACTIVATION <var>]
EVENTS
• This is similar to the previous examples. All changes are marked with red.
There have been no changes to the subclasses, only to the super class and
the report, so the code for the subclasses is not shown.