oops-abap
TRANSCRIPT
![Page 1: OOPS-ABAP](https://reader035.vdocuments.net/reader035/viewer/2022062614/546f635ab4af9fb87a8b4766/html5/thumbnails/1.jpg)
Hyderabad February 24-26th 2009
Instructor: Subhas Katikala.
Object Oriented ABAP
![Page 2: OOPS-ABAP](https://reader035.vdocuments.net/reader035/viewer/2022062614/546f635ab4af9fb87a8b4766/html5/thumbnails/2.jpg)
Workshop Goals
This workshop will enable you to:
• Learn object – oriented concepts.
• Learn the principle of object - oriented programming.
• Learn the application of object
- oriented ABAP.
![Page 3: OOPS-ABAP](https://reader035.vdocuments.net/reader035/viewer/2022062614/546f635ab4af9fb87a8b4766/html5/thumbnails/3.jpg)
Course Contents
Object Oriented ConceptsObject Oriented Programming.Advantages of the Object-Oriented Approach
Methods• Syntax and Visibility• Instance Methods and Static Methods• Constructor
Reference Variables• Creating References• Assigning References
ClassesComponents of a Class
Attributes• Syntax and Visibility• Instance Attributes and Static Attributes
![Page 4: OOPS-ABAP](https://reader035.vdocuments.net/reader035/viewer/2022062614/546f635ab4af9fb87a8b4766/html5/thumbnails/4.jpg)
Course Contents
Inheritance Super classes and Subclasses Visibility Inheritance and the (Instance) Constructor Parameters Redefining Methods in OOABAP Compatibility Principles of the Narrowing Cast Static and Dynamic Components Final Classes and Methods
![Page 5: OOPS-ABAP](https://reader035.vdocuments.net/reader035/viewer/2022062614/546f635ab4af9fb87a8b4766/html5/thumbnails/5.jpg)
Course Contents
Polymorphism Advantages Compared to Procedural Programming Abstract Classes and Methods Component Namespaces in Classes
Interfaces Defining and Implementing an Interface Working with Interface Components Interface References
• Narrowing Cast• Widening Cast
Using Several Interfaces Polymorphism and Interfaces Polymorphism and Inheritance Compound Interfaces
![Page 6: OOPS-ABAP](https://reader035.vdocuments.net/reader035/viewer/2022062614/546f635ab4af9fb87a8b4766/html5/thumbnails/6.jpg)
Course Contents
Events Define and Trigger Events Handle Events Register and deregister Events Receive a reference from Sender
![Page 7: OOPS-ABAP](https://reader035.vdocuments.net/reader035/viewer/2022062614/546f635ab4af9fb87a8b4766/html5/thumbnails/7.jpg)
Object – Oriented Concepts
What are Objects ?
SAP AG 1999
What Are Objects?
Tree
House
Crane
Objects are an abstraction of the real world
Objects are units made up of data and of the functions belonging to that data
Real worldModel
DataMethodMethodMethod
DataMethodMethodMethod
DataMethodMethodMethod
Boat
DataMethodMethodMethod
![Page 8: OOPS-ABAP](https://reader035.vdocuments.net/reader035/viewer/2022062614/546f635ab4af9fb87a8b4766/html5/thumbnails/8.jpg)
Object Oriented Programming
• Encapsulation
• Inheritance
• Polymorphism
• Instantiation
• Interfacing
• Events
OOPS
![Page 9: OOPS-ABAP](https://reader035.vdocuments.net/reader035/viewer/2022062614/546f635ab4af9fb87a8b4766/html5/thumbnails/9.jpg)
Advantages
• Simplicity
• Explicitness
• Maintainability
• Future Orientation
![Page 10: OOPS-ABAP](https://reader035.vdocuments.net/reader035/viewer/2022062614/546f635ab4af9fb87a8b4766/html5/thumbnails/10.jpg)
• Classes are the central element of object-orientation.
• A Class is an abstract description of an object.
• Classes are templates for objects.
• The attributes of objects are defined by the components of the class, which describe the state and behavior of objects.
Classes
![Page 11: OOPS-ABAP](https://reader035.vdocuments.net/reader035/viewer/2022062614/546f635ab4af9fb87a8b4766/html5/thumbnails/11.jpg)
• You define global classes and interfaces in the Class Builder (Transaction SE24) in the ABAP Workbench.
• They are stored centrally in class pools in the class library in the R/3 Repository.
• All of the ABAP programs in an R/3 System can access the global classes.
Classes
![Page 12: OOPS-ABAP](https://reader035.vdocuments.net/reader035/viewer/2022062614/546f635ab4af9fb87a8b4766/html5/thumbnails/12.jpg)
Components in a class
![Page 13: OOPS-ABAP](https://reader035.vdocuments.net/reader035/viewer/2022062614/546f635ab4af9fb87a8b4766/html5/thumbnails/13.jpg)
Defining Local Classes
• A complete class definition consists of a declaration part and, if required, an implementation part.
• The declaration part of a class <class> is a statement block: CLASS c1 DEFINITION. …. ENDCLASS.
• If you declare methods in the declaration part of a class, you must also write an implementation part for it.
CLASS c1 IMPLEMENTATION. …. ENDCLASS.
Classes
![Page 14: OOPS-ABAP](https://reader035.vdocuments.net/reader035/viewer/2022062614/546f635ab4af9fb87a8b4766/html5/thumbnails/14.jpg)
Attributes
![Page 15: OOPS-ABAP](https://reader035.vdocuments.net/reader035/viewer/2022062614/546f635ab4af9fb87a8b4766/html5/thumbnails/15.jpg)
Defining Local Classes
Classes
![Page 16: OOPS-ABAP](https://reader035.vdocuments.net/reader035/viewer/2022062614/546f635ab4af9fb87a8b4766/html5/thumbnails/16.jpg)
Attributes, Types, Constants - Syntax
![Page 17: OOPS-ABAP](https://reader035.vdocuments.net/reader035/viewer/2022062614/546f635ab4af9fb87a8b4766/html5/thumbnails/17.jpg)
Attributes and Visibility
![Page 18: OOPS-ABAP](https://reader035.vdocuments.net/reader035/viewer/2022062614/546f635ab4af9fb87a8b4766/html5/thumbnails/18.jpg)
Instance attributes and Static attributes
![Page 19: OOPS-ABAP](https://reader035.vdocuments.net/reader035/viewer/2022062614/546f635ab4af9fb87a8b4766/html5/thumbnails/19.jpg)
Methods
![Page 20: OOPS-ABAP](https://reader035.vdocuments.net/reader035/viewer/2022062614/546f635ab4af9fb87a8b4766/html5/thumbnails/20.jpg)
Methods : Syntax
![Page 21: OOPS-ABAP](https://reader035.vdocuments.net/reader035/viewer/2022062614/546f635ab4af9fb87a8b4766/html5/thumbnails/21.jpg)
Methods and Visibility
![Page 22: OOPS-ABAP](https://reader035.vdocuments.net/reader035/viewer/2022062614/546f635ab4af9fb87a8b4766/html5/thumbnails/22.jpg)
Instance methods and Static methods
![Page 23: OOPS-ABAP](https://reader035.vdocuments.net/reader035/viewer/2022062614/546f635ab4af9fb87a8b4766/html5/thumbnails/23.jpg)
Instance methods and Static methods : Example
![Page 24: OOPS-ABAP](https://reader035.vdocuments.net/reader035/viewer/2022062614/546f635ab4af9fb87a8b4766/html5/thumbnails/24.jpg)
Constructor
![Page 25: OOPS-ABAP](https://reader035.vdocuments.net/reader035/viewer/2022062614/546f635ab4af9fb87a8b4766/html5/thumbnails/25.jpg)
Constructor : Example
![Page 26: OOPS-ABAP](https://reader035.vdocuments.net/reader035/viewer/2022062614/546f635ab4af9fb87a8b4766/html5/thumbnails/26.jpg)
Static Constructor : Implementation
![Page 27: OOPS-ABAP](https://reader035.vdocuments.net/reader035/viewer/2022062614/546f635ab4af9fb87a8b4766/html5/thumbnails/27.jpg)
Static Constructor : Call Examples
![Page 28: OOPS-ABAP](https://reader035.vdocuments.net/reader035/viewer/2022062614/546f635ab4af9fb87a8b4766/html5/thumbnails/28.jpg)
Creating Objects
![Page 29: OOPS-ABAP](https://reader035.vdocuments.net/reader035/viewer/2022062614/546f635ab4af9fb87a8b4766/html5/thumbnails/29.jpg)
Reference Variables
![Page 30: OOPS-ABAP](https://reader035.vdocuments.net/reader035/viewer/2022062614/546f635ab4af9fb87a8b4766/html5/thumbnails/30.jpg)
Creating Objects : Syntax
![Page 31: OOPS-ABAP](https://reader035.vdocuments.net/reader035/viewer/2022062614/546f635ab4af9fb87a8b4766/html5/thumbnails/31.jpg)
Assigning References
![Page 32: OOPS-ABAP](https://reader035.vdocuments.net/reader035/viewer/2022062614/546f635ab4af9fb87a8b4766/html5/thumbnails/32.jpg)
• Inheritance allows you to derive a new class from an existing class. • You do this using the INHERITING FROM addition in the
CLASS <subclass> DEFINITION INHERITING FROM <superclass>
statement.• The new class <subclass> inherits all of the components of the existing
class <superclass>. • The new class is called the subclass of the class from which it is
derived. • The original class is called the superclass of the new class.
Inheritance
![Page 33: OOPS-ABAP](https://reader035.vdocuments.net/reader035/viewer/2022062614/546f635ab4af9fb87a8b4766/html5/thumbnails/33.jpg)
Inheritance
![Page 34: OOPS-ABAP](https://reader035.vdocuments.net/reader035/viewer/2022062614/546f635ab4af9fb87a8b4766/html5/thumbnails/34.jpg)
Inheritance : Syntax
![Page 35: OOPS-ABAP](https://reader035.vdocuments.net/reader035/viewer/2022062614/546f635ab4af9fb87a8b4766/html5/thumbnails/35.jpg)
Relationships between super classes and subclasses
Relationships between super classes and subclasses
![Page 36: OOPS-ABAP](https://reader035.vdocuments.net/reader035/viewer/2022062614/546f635ab4af9fb87a8b4766/html5/thumbnails/36.jpg)
Inheritance and Visibility
![Page 37: OOPS-ABAP](https://reader035.vdocuments.net/reader035/viewer/2022062614/546f635ab4af9fb87a8b4766/html5/thumbnails/37.jpg)
Inheritance and (Instance) constructor
![Page 38: OOPS-ABAP](https://reader035.vdocuments.net/reader035/viewer/2022062614/546f635ab4af9fb87a8b4766/html5/thumbnails/38.jpg)
Parameters and CREATE OBJECT
![Page 39: OOPS-ABAP](https://reader035.vdocuments.net/reader035/viewer/2022062614/546f635ab4af9fb87a8b4766/html5/thumbnails/39.jpg)
Redefining Methods in ABAP Objects
![Page 40: OOPS-ABAP](https://reader035.vdocuments.net/reader035/viewer/2022062614/546f635ab4af9fb87a8b4766/html5/thumbnails/40.jpg)
Redefining Methods : Example
![Page 41: OOPS-ABAP](https://reader035.vdocuments.net/reader035/viewer/2022062614/546f635ab4af9fb87a8b4766/html5/thumbnails/41.jpg)
Compatibility and Narrowing Cast
![Page 42: OOPS-ABAP](https://reader035.vdocuments.net/reader035/viewer/2022062614/546f635ab4af9fb87a8b4766/html5/thumbnails/42.jpg)
Principles of the Narrowing Cast
![Page 43: OOPS-ABAP](https://reader035.vdocuments.net/reader035/viewer/2022062614/546f635ab4af9fb87a8b4766/html5/thumbnails/43.jpg)
Static and Dynamic Types: Example
![Page 44: OOPS-ABAP](https://reader035.vdocuments.net/reader035/viewer/2022062614/546f635ab4af9fb87a8b4766/html5/thumbnails/44.jpg)
Static and Dynamic Types for References
![Page 45: OOPS-ABAP](https://reader035.vdocuments.net/reader035/viewer/2022062614/546f635ab4af9fb87a8b4766/html5/thumbnails/45.jpg)
Widening the Cast
Static and Dynamic Types for References
![Page 46: OOPS-ABAP](https://reader035.vdocuments.net/reader035/viewer/2022062614/546f635ab4af9fb87a8b4766/html5/thumbnails/46.jpg)
Widening the cast
![Page 47: OOPS-ABAP](https://reader035.vdocuments.net/reader035/viewer/2022062614/546f635ab4af9fb87a8b4766/html5/thumbnails/47.jpg)
Polymorphism
![Page 48: OOPS-ABAP](https://reader035.vdocuments.net/reader035/viewer/2022062614/546f635ab4af9fb87a8b4766/html5/thumbnails/48.jpg)
Polymorphism
![Page 49: OOPS-ABAP](https://reader035.vdocuments.net/reader035/viewer/2022062614/546f635ab4af9fb87a8b4766/html5/thumbnails/49.jpg)
Polymorphism
![Page 50: OOPS-ABAP](https://reader035.vdocuments.net/reader035/viewer/2022062614/546f635ab4af9fb87a8b4766/html5/thumbnails/50.jpg)
• Interfaces exclusively describe the external point of contact of a class, but they do not contain their own implementation part.
Interface
![Page 51: OOPS-ABAP](https://reader035.vdocuments.net/reader035/viewer/2022062614/546f635ab4af9fb87a8b4766/html5/thumbnails/51.jpg)
Defining and Implementing Interface
![Page 52: OOPS-ABAP](https://reader035.vdocuments.net/reader035/viewer/2022062614/546f635ab4af9fb87a8b4766/html5/thumbnails/52.jpg)
Working with Interface components
![Page 53: OOPS-ABAP](https://reader035.vdocuments.net/reader035/viewer/2022062614/546f635ab4af9fb87a8b4766/html5/thumbnails/53.jpg)
Interface References Narrowing casting
![Page 54: OOPS-ABAP](https://reader035.vdocuments.net/reader035/viewer/2022062614/546f635ab4af9fb87a8b4766/html5/thumbnails/54.jpg)
• The assignment of an object reference to an interface reference is known as a narrowing cast since, as with inheritance, only a part of the object interface is visible once you have assigned the reference.
• With an interface reference, you can no longer address all components in the class carrying out the implementation, but
only the components defined in the interface.
Interface
![Page 55: OOPS-ABAP](https://reader035.vdocuments.net/reader035/viewer/2022062614/546f635ab4af9fb87a8b4766/html5/thumbnails/55.jpg)
Interface references widening cast
![Page 56: OOPS-ABAP](https://reader035.vdocuments.net/reader035/viewer/2022062614/546f635ab4af9fb87a8b4766/html5/thumbnails/56.jpg)
• The widening cast is, as with inheritance, the opposite of the narrowing cast: here it is used to retrieve an object reference from an interface reference. Obviously it cannot be statically checked, since an interface can be implemented by more than one class.
• An object reference cannot be assigned to an interface reference if it has itself not implemented the corresponding interface.
Interface
![Page 57: OOPS-ABAP](https://reader035.vdocuments.net/reader035/viewer/2022062614/546f635ab4af9fb87a8b4766/html5/thumbnails/57.jpg)
• In the above example, one class is implementing several interfaces. Even if these interfaces contain components with the same name, they are differentiated in the class carrying out the
implementation by the prefix “<interfacename>~”.
Using several Interface
![Page 58: OOPS-ABAP](https://reader035.vdocuments.net/reader035/viewer/2022062614/546f635ab4af9fb87a8b4766/html5/thumbnails/58.jpg)
Polymorphism and Interface
![Page 59: OOPS-ABAP](https://reader035.vdocuments.net/reader035/viewer/2022062614/546f635ab4af9fb87a8b4766/html5/thumbnails/59.jpg)
• Objects or Classes use events to trigger Event Handler methods in other objects or classes.
• When an event is triggered any number of Event Handler Methods can be called.
• The events of a class can be raised in the same class using the RAISE EVENT Statement.
• Events have only output parameters which are accepted by the Event Handler Methods as input parameters.
• The link between the trigger and the handler is established dynamically at runtime using the statement SET HANDLER.
Events
![Page 60: OOPS-ABAP](https://reader035.vdocuments.net/reader035/viewer/2022062614/546f635ab4af9fb87a8b4766/html5/thumbnails/60.jpg)
Events Overview
![Page 61: OOPS-ABAP](https://reader035.vdocuments.net/reader035/viewer/2022062614/546f635ab4af9fb87a8b4766/html5/thumbnails/61.jpg)
Triggering and handling Events : Overview
![Page 62: OOPS-ABAP](https://reader035.vdocuments.net/reader035/viewer/2022062614/546f635ab4af9fb87a8b4766/html5/thumbnails/62.jpg)
Defining and Triggering Events
![Page 63: OOPS-ABAP](https://reader035.vdocuments.net/reader035/viewer/2022062614/546f635ab4af9fb87a8b4766/html5/thumbnails/63.jpg)
Handling and Registering Events
![Page 64: OOPS-ABAP](https://reader035.vdocuments.net/reader035/viewer/2022062614/546f635ab4af9fb87a8b4766/html5/thumbnails/64.jpg)
Handling Events
![Page 65: OOPS-ABAP](https://reader035.vdocuments.net/reader035/viewer/2022062614/546f635ab4af9fb87a8b4766/html5/thumbnails/65.jpg)
Registering for an Event : Syntax
![Page 66: OOPS-ABAP](https://reader035.vdocuments.net/reader035/viewer/2022062614/546f635ab4af9fb87a8b4766/html5/thumbnails/66.jpg)
Deregistration
![Page 67: OOPS-ABAP](https://reader035.vdocuments.net/reader035/viewer/2022062614/546f635ab4af9fb87a8b4766/html5/thumbnails/67.jpg)
Registration/Deregistration : Handler Table
![Page 68: OOPS-ABAP](https://reader035.vdocuments.net/reader035/viewer/2022062614/546f635ab4af9fb87a8b4766/html5/thumbnails/68.jpg)
Event handling : Characteristics
![Page 69: OOPS-ABAP](https://reader035.vdocuments.net/reader035/viewer/2022062614/546f635ab4af9fb87a8b4766/html5/thumbnails/69.jpg)
Events and Visibility