0601 abap objects
TRANSCRIPT
-
7/27/2019 0601 ABAP Objects
1/19
ABAP Objects
-
7/27/2019 0601 ABAP Objects
2/19
Describe the Advantages of Object Orientation
Define Classes, Attributes, and Methods
Define the Reference Concept
Describe Interfaces and Events
Topic Objectives
-
7/27/2019 0601 ABAP Objects
3/19
Advantages of Object Orientation
Encapsulation Interface Creation
Integration of ExternalObject Models
Distribution
Support of GUIand Workflow
Generic Programmingand Reusability
-
7/27/2019 0601 ABAP Objects
4/19
Encapsulation
Object: Flight
Method: book
Data: passenger_list
Program: . . .
add 1 to passenger_list
Program: . . .
Read table passenger_list
No
access
-
7/27/2019 0601 ABAP Objects
5/19
Function Modules vs. Objects
GUI SessionInternal Session of
ABAP Program
Function
Group1 withdata
Function
Group Nwith data
ABAP Program with data
Internal Session ofABAP ProgramGUI Session
ABAP Program with data
Function Group/ Module Objects
Objects
of Class 1with data
Objects of
Class Nwith data
-
7/27/2019 0601 ABAP Objects
6/19
Overview of Object-Oriented
Concepts
A object is a self-contained entity having astate, a behavior, and an identity.
-
7/27/2019 0601 ABAP Objects
7/19
Object Attributes
PassengerList
Public
Access
Private Access
CARRID
CONNID
Method: BOOK
LH
0400FLDATE1998-
01-
26
MillerCarter
Smith
-
7/27/2019 0601 ABAP Objects
8/19
Objects Belonging to Classes
InstancesInstances
Class Flight Class Hotel
-
7/27/2019 0601 ABAP Objects
9/19
Classes
CLASS DEFINITION.
* INHERITING FROM -- available in a later 4.0 version
PUBLIC SECTION.
definition of components visible outside the class
PROTECTED SECTION.
definition of components only visible to subclasses of
this class.
PRIVATE SECTION.
definition of components only visible within the class
ENDCLASS.
CLASS IMPLEMENTATION.
method implementations
ENDCLASS.
-
7/27/2019 0601 ABAP Objects
10/19
Class Components: Attributes &
Methods
{DATA | CLASS-DATA} attr TYPE type
[ VALUE val ]
[ READ-ONLY ]
[ VIRTUAL [ SET-METHOD set-method ]
[ GET-METHOD get-method ] ].
CONSTANTS const TYPE type VALUE val.
{METHODS | CLASS-METHODS} method
[ IMPORTING ][ EXPORTING ]
[ CHANGING ]
[ EXCEPTIONS ]
[ RETURNING result TYPE t ].
-
7/27/2019 0601 ABAP Objects
11/19
Reference Concept
Object ReferenceObject Reference
Instances
-
7/27/2019 0601 ABAP Objects
12/19
The Reference Concept Example
REPORT Flightdemo.
TYPES: tpassenger(20).
CLASS c_flight DEFINITION.
PUBLIC SECTION.
DATA: carrid like spfli-carrid,
connid like spfli-connid,
fldate like spfli-fldate.
METHODS: book IMPORTING passenger TYPE tpassenger.
PRIVATE SECTION.
DATA: passengerlist type tpassenger occurs 10.ENDCLASS.
CLASS c_flight IMPLEMENTATION.
METHOD book.
APPEND passenger to passengerlist.
ENDMETHOD.
ENDCLASS.
START-OF-SELECTION.DATA: flight TYPE REF to c_flight.
CREATE OBJECT flight.
Flight->carrid = LH.
Flight->connid = 0567.
Flight->fldate = 19970908.
CALL METHOD flight->book EXPORTING passenger = Peter Miller.
b
-
7/27/2019 0601 ABAP Objects
13/19
Interfaces
InstancesInstances
Class FlightClass Hotel
Interface Reservation
G i P i ith
-
7/27/2019 0601 ABAP Objects
14/19
Generic Programming with
Interfaces
INTERFACE interface.
[ INTERFACES ]
[ ]
ENDINTERFACE.
-
7/27/2019 0601 ABAP Objects
15/19
Example of Programming Interface
-
7/27/2019 0601 ABAP Objects
16/19
Events
Event Source
Event raising classEvent Handling Classes
Event Table
-
7/27/2019 0601 ABAP Objects
17/19
Event & Event Handlers Example
CLASS CGUIbutton DEFINITION.
PUBLIC SECTION.METHODS: SetLabel
IMPORTING
txt TYPE .
EVENTS: Clicked
EXPORTING
doubleclick TYPE I.
ENDCLASS.
CLASS CGUIbutton IMPLEMENTATION.
METHOD anymethod.
RAISE EVENT Clicked
EXPORTING doubleclick = 0.
ENDMETHOD.
ENDCLASS.
CLASS window1 DEFINITION.
PUBLIC SECTION.
INTERFACES EVENTS OF CGUIbuttonAS: OKBtn, CancelBtn.
DATA: OK TYPE REF TO
CGUIbutton.
ENDCLASS.
CLASS window1 IMPLEMENTATION.
METHOD init.
CREATE OBJECT OK.SET HANDLEROKBtn FOR EVENTS
OF OK.
ENDMETHOD.
METHOD OKBtn~Clicked.
If doubleclick = 1.
Endif.ENDMETHOD.
METHOD CancelBtn~Clicked.
ENDMETHOD.
ENDCLASS.
-
7/27/2019 0601 ABAP Objects
18/19
Exercise 47 - Creating and Using a Class, 60 minutes
Exercise
-
7/27/2019 0601 ABAP Objects
19/19
Any questions?
Questions and Answers