ABAP Objects
6-ABAP.1
This is PricewaterhouseCoopers PROPRIETARY MATERIAL (hereafter, the Material) intended for internal use only.
You may not rent, lease or distribute the Material to clients or other third parties, but you may transfer the Material to
other employees of PricewaterhouseCoopers.
Introduction to
ABAP Objects
6-ABAP.2
This is PricewaterhouseCoopers PROPRIETARY MATERIAL (hereafter, the Material) intended for internal use only.
You may not rent, lease or distribute the Material to clients or other third parties, but you may transfer the Material to
other employees of PricewaterhouseCoopers.
What Is an Object?
Data
Data
Method
Method
Method
ABAP Objects
6-ABAP.3
This is PricewaterhouseCoopers PROPRIETARY MATERIAL (hereafter, the Material) intended for internal use only.
You may not rent, lease or distribute the Material to clients or other third parties, but you may transfer the Material to
other employees of PricewaterhouseCoopers.
Class
Objects
Classes
ABAP Objects
6-ABAP.5
This is PricewaterhouseCoopers PROPRIETARY MATERIAL (hereafter, the Material) intended for internal use only.
You may not rent, lease or distribute the Material to clients or other third parties, but you may transfer the Material to
other employees of PricewaterhouseCoopers.
ABAP Objects
• An extension to the ABAP language
• Backward-compatible
• Interchangeable with standard ABAP
ABAP Objects
6-ABAP.6
This is PricewaterhouseCoopers PROPRIETARY MATERIAL (hereafter, the Material) intended for internal use only.
You may not rent, lease or distribute the Material to clients or other third parties, but you may transfer the Material to
other employees of PricewaterhouseCoopers.
ABAP Objects Programming
Class
Declaration
Provides a list of the
attributes and
methods available in
the class
Class
Implementation
The ABAP code that
implements the
defined methods
Using ABAP
Objects
How to use ABAP
objects in an ABAP
program
ABAP Objects
6-ABAP.7
This is PricewaterhouseCoopers PROPRIETARY MATERIAL (hereafter, the Material) intended for internal use only.
You may not rent, lease or distribute the Material to clients or other third parties, but you may transfer the Material to
other employees of PricewaterhouseCoopers.
Class Definition
CLASS number DEFINITION.
PUBLIC SECTION.
METHODS: write_value,
set_value IMPORTING VALUE(new_value) TYPE
I,
increment.
PRIVATE SECTION.
DATA value TYPE I.
ENDCLASS.
Method definition
Attribute definition
ABAP Objects
6-ABAP.9
This is PricewaterhouseCoopers PROPRIETARY MATERIAL (hereafter, the Material) intended for internal use only.
You may not rent, lease or distribute the Material to clients or other third parties, but you may transfer the Material to
other employees of PricewaterhouseCoopers.
Class Implementation
CLASS number IMPLEMENTATION.
METHOD increment.
ADD 1 TO value.
ENDMETHOD.
METHOD set_value.
value = new_value.
ENDMETHOD.
METHOD write_value.
WRITE: / 'The number is', value.
ENDMETHOD.
ENDCLASS.
Implementation
of a method
ABAP Objects
6-ABAP.10
This is PricewaterhouseCoopers PROPRIETARY MATERIAL (hereafter, the Material) intended for internal use only.
You may not rent, lease or distribute the Material to clients or other third parties, but you may transfer the Material to
other employees of PricewaterhouseCoopers.
Using a Class
REPORT z_object_demo.
DATA: count TYPE REF TO number.
START-OF-SELECTION.
CREATE OBJECT count.
CALL METHOD count->set_value EXPORTING new_value = 5.
CALL METHOD count->write_value.
DO 3 TIMES.
CALL METHOD count->increment.
ENDDO.
CALL METHOD count->write_value.
Declares an
object variable
Instantiates an
object
Method calls
ABAP Objects
6-ABAP.11
This is PricewaterhouseCoopers PROPRIETARY MATERIAL (hereafter, the Material) intended for internal use only.
You may not rent, lease or distribute the Material to clients or other third parties, but you may transfer the Material to
other employees of PricewaterhouseCoopers.
Using a Class
Reference Variables
DATA: count TYPE REF TO number.
count
Number
object
CREATE OBJECT count.
ABAP Objects
6-ABAP.13
This is PricewaterhouseCoopers PROPRIETARY MATERIAL (hereafter, the Material) intended for internal use only.
You may not rent, lease or distribute the Material to clients or other third parties, but you may transfer the Material to
other employees of PricewaterhouseCoopers.
Using a Class
Objects in Internal Tables
DATA: count TYPE REF TO number
count_table TYPE TABLE OF REF TO number.
CREATE OBJECT count.
APPEND count TO count_table.
CREATE OBJECT count.
APPEND count TO count_table.
Number
object 1
count_table
Number
object 2
ABAP Objects
6-ABAP.14
This is PricewaterhouseCoopers PROPRIETARY MATERIAL (hereafter, the Material) intended for internal use only.
You may not rent, lease or distribute the Material to clients or other third parties, but you may transfer the Material to
other employees of PricewaterhouseCoopers.
Using a Class
Calling Methods
CALL METHOD count->set_value
EXPORTING
new_value = 5.
CALL METHOD count->write_value.
DO 3 TIMES.
CALL METHOD count->increment.
ENDDO.
CALL METHOD count->write_value.
Use Function
Module syntax
for parameters
ABAP Objects
6-ABAP.15
This is PricewaterhouseCoopers PROPRIETARY MATERIAL (hereafter, the Material) intended for internal use only.
You may not rent, lease or distribute the Material to clients or other third parties, but you may transfer the Material to
other employees of PricewaterhouseCoopers.
Constructors
CLASS number DEFINITION.
PUBLIC SECTION.
METHODS: CONSTRUCTOR IMPORTING start_value TYPE
I.
ENDCLASS.
CLASS number IMPLEMENTATION.
METHOD CONSTRUCTOR.
* code to initialize the object
ENDMETHOD.
ENDCLASS.
DATA count TYPE REF TO number.
CREATE OBJECT count
EXPORTING start_value = 6.
The constructor is
automatically executed
when the object is
instantiated
ABAP Objects
6-ABAP.16
This is PricewaterhouseCoopers PROPRIETARY MATERIAL (hereafter, the Material) intended for internal use only.
You may not rent, lease or distribute the Material to clients or other third parties, but you may transfer the Material to
other employees of PricewaterhouseCoopers.
STATIC Class Members
CLASS number DEFINITION.
PUBLIC SECTION.
CLASS-METHODS:
get_count EXPORTING count TYPE I.
PRIVATE SECTION.
CLASS-DATA:
number_of_objects TYPE I.
ENDCLASS.
CLASS number IMPLEMENTATION.
METHOD get_count.
count = number_of_objects.
ENDMETHOD.
ENDCLASS.
DATA x TYPE I.
number=>get_count
IMPORTING count = x.
Static members
belong to
the class, not the
object
Call a static method
with the
class name and "=>"
ABAP Objects
6-ABAP.18
This is PricewaterhouseCoopers PROPRIETARY MATERIAL (hereafter, the Material) intended for internal use only.
You may not rent, lease or distribute the Material to clients or other third parties, but you may transfer the Material to
other employees of PricewaterhouseCoopers.
Class E
Class B
Class D
Class C
Derived Class
Super Class
Super Class
Class Inheritance
Class A
ABAP Objects
6-ABAP.19
This is PricewaterhouseCoopers PROPRIETARY MATERIAL (hereafter, the Material) intended for internal use only.
You may not rent, lease or distribute the Material to clients or other third parties, but you may transfer the Material to
other employees of PricewaterhouseCoopers.
Inheritance in ABAP
CLASS imaginary_number DEFINITION
INHERITING FROM number.
PUBLIC SECTION.
DATA imaginary_part TYPE I.
ENDCLASS.
ABAP Objects
6-ABAP.20
This is PricewaterhouseCoopers PROPRIETARY MATERIAL (hereafter, the Material) intended for internal use only.
You may not rent, lease or distribute the Material to clients or other third parties, but you may transfer the Material to
other employees of PricewaterhouseCoopers.
The Control Framework
SAP AG 1999
CFW as Seen by the Programmer: Classes
CL_GUI_CONTROL
CL_GUI_OBJ ECT
CL_GUI_CONTAINER
• CL_GUI_CUSTOM_CONTAINER
• CL_GUI_DOCKING_CONTAINER
• CL_GUI_SPLITTER_CONTAINER
• CL_GUI_EASY_SPLITTER_CONTAINER
• CL_GUI_DIALOGBOX_CONTAINER
CL_GUI_PICTURE
CL_GUI_HTML_VIEWER
CL_GUI_TEXTEDIT
CL_GUI_ . . .
CL_GUI_ALV_GRID
CL_GUI_TREE_CONTROL
ABAP Objects
6-ABAP.21
This is PricewaterhouseCoopers PROPRIETARY MATERIAL (hereafter, the Material) intended for internal use only.
You may not rent, lease or distribute the Material to clients or other third parties, but you may transfer the Material to
other employees of PricewaterhouseCoopers.
Global vs. Local Classes
Global Classes
Local Classes
Can be accessed
from
Any program
Only the program
where it is defined
Where Stored
In the Class
Repository
In the program
where it is defined
Where Created
With the Class
Builder (SE24)
With the ABAP
Editor
Namespace
Must begin with Y
or Z
Any
You can define a class to be global or local.
ABAP Objects
6-ABAP.22
This is PricewaterhouseCoopers PROPRIETARY MATERIAL (hereafter, the Material) intended for internal use only.
You may not rent, lease or distribute the Material to clients or other third parties, but you may transfer the Material to
other employees of PricewaterhouseCoopers.
The Class Builder Utility
ABAP Objects
6-ABAP.23
This is PricewaterhouseCoopers PROPRIETARY MATERIAL (hereafter, the Material) intended for internal use only.
You may not rent, lease or distribute the Material to clients or other third parties, but you may transfer the Material to
other employees of PricewaterhouseCoopers.
ABAP Objects
Advantages and Disadvantages
• Advantages of using ABAP Objects
– Consistency in the development process
– Improves reuse of components
– Improves system maintenance
– Eases external object-based interfaces
• Disadvantages of using ABAP Objects
– Longer development time
– Requires experienced developers
– Database is not object-oriented
– Slower performance