Abap Oo Basics

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 20

BBS 2:

ABAP OO Basics
ABAP OO Basics
An object is a self-contained entity having a
state, a behavior, and an identity.
ABAP OO Basics


THE MINDSET
Classical ABAP: Declaration
Internal Table Declaration:

TYPES: BEGIN OF ty_out,
num TYPE i,
END OF ty_out.

TYPES: ty_tt_out TYPE STANDARD TABLE OF ty_out,
ty_ts_out TYPE SORTED TABLE OF ty_out,
ty_th_out TYPE HASHED TABLE OF ty_out.

DATA: i_out TYPE ty_tt_out,
is_out TYPE ty_ts_out,
ih_out TYPE ty_th_out.
Classical ABAP: Modularization
For maintainability and reusability
There should be NO direct access to global
variables, internal tables, and work areas
directly
Subroutine interface parameters:
USING
CHANGING
Classical ABAP: Examples

Geeky Example #1

Modularized Geeky Example #1

Fibonacci Series:
1 1 2 3 5 8 13 21 34
Prime Numbers: Divisible only by the number
itself and 1
Classical ABAP: Function Modules
Are processed blocks with a defined
interface
transparent, separate, independent
Have source codes that come between
the ABAP stmts: FUNCTION
ENDFUNCTION.
Belong to FUNCTION GROUPS
Are called using the ABAP statement:
CALL FUNCTION <function module name>
<interface parameters>.
Classical ABAP: Examples

Function Module Geeky Example #1

TABLES are not used

Object Templates: Classes

Instances
Instances
Class Flight
Class Hotel
ABAP OO: Classes
Class Components:
ATTRIBUTES
define the internal state of an object
store an objects properties which can be public,
private, or protected

METHODS
the objects means of performing operations
have an interface similar to function modules

ABAP OO: Classes
{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 <list of import parameters> ]
[ EXPORTING <list of export parameters> ]
[ CHANGING <list of import/export parameters> ]
[ EXCEPTIONS <list of export exceptions> ]
[ RETURNING result TYPE t ].
ABAP OO: Classes
CLASS <class> DEFINITION.
* INHERITING FROM <superclass> -- 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 <class> IMPLEMENTATION.
method implementations
ENDCLASS.
ABAP OO: Example

LOCAL Class version of Geeky Example #1

GLOBAL Class version of Geeky Example #1
ABAP OO: Example

Modularized Geeky Example #2

Retrieve material numbers from table MSEG and
then display these material numbers and their
corresponding descriptions. Include
validations on the material and plant.
ABAP OO: Exercise

Create an ABAP OO-version of Modularized
Geeky Example #2



Create the other ABAP Objects necessary: Global Class, Structures, Table
Types, Data Elements, Domains


ABAP OO: Definitions
Constructor
Instance constructors - executed every time an object
(instance) is created with the CREATE OBJECT statement
Class constructors - executed exactly once before you
first access a class
Interfaces
are implemented in addition to, and independently of
classes
will only have a declaration part
are listed in the definition part of the class, and must
always be in the PUBLIC SECTION
ABAP OO: Definitions
Events
Model state changes for an object
Are triggered with the RAISE EVENT statement which
would call all event handlers that have been registered
for this event using the SET HANDLER statement
Event Handlers
Methods to handle events raised by other objects
ABAP OO: Definitions
Inheritance
an existing class is used to derive a new class (child
class).
the new class contains the attributes of the parent class
plus the new attributes and methods added to it.
the child class derives all the attributes and methods
declared in parent class as PUBLIC.
the child class cannot inherit private members.
the protected members in parent class are derived in
child class but their visibility changes to private.
ABAP OO: Definitions
Polymorphism
name of method is the same but they behave
differently in different classes
implementation of method (i.e. body of the method) is
different in different classes. It can be achieved in two
different ways in OO ABAP.
Interfaces
Overriding methods or redefining methods in each class after
inheritance

Brown Bag Sessions Schedule
29Jun: Basic Optimization Techniques

12Jul : ABAP OO Basics
19Jul : Webdynpro for ABAP Basics
26Jul : Possible Topics:
Basic Optimization Techniques II
SAP Adobe Interactive Forms

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy