Introducing Abap Objects

  • Uploaded by: api-3834175
  • 0
  • 0
  • November 2019
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Introducing Abap Objects as PDF for free.

More details

  • Words: 1,343
  • Pages: 32
Object Oriented ABAP Introducing ABAP Objects

Introduction to ABAP Objects • ABAP Objects, the object-oriented (OO) extension to the ABAP language, is available with releases 4.5 and 4.6. Release 4.6 adds inheritance, nested interfaces, and dynamic method invocation. In this training, we’ll take you through an introduction to ABAP Objects and give you a comprehensive example (The code for the example can be tested and debugged in DEMO_ABAP_OBJECTS program in R/3 release 4.6 or higher). 2

The ASPplus Solutions Compan

What are ABAP Objects ? • ABAP objects are compatible extension of the existing ABAP language. • You can use existing ABAP statements within ABAP objects. • You can use ABAP objects within existing programs. • ABAP objects are fully integrated in ABAP debugger. 3

The ASPplus Solutions Compan

Continued…. • The term has two meanings • On one hand, it stands for the entire ABAP runtime environment. • On the other hand, it represents the object oriented extension of the ABAP language.

4

The ASPplus Solutions Compan

ABAP objects are created because • The Business Object Repository(BOR) already presented an OO view of the system to the outside, and we wanted a common programming model for both outside and inside. • We wanted seamless integration with external object modules (DCOM and CORBA). 5

The ASPplus Solutions Compan

Continued… • We wanted the potential benefits of objects with in R/3, including better control of complexity, a better means for encapsulation, extensibility, and reuse, and a language basis for patterns and frameworks. • We needed objects to be the foundation for a new GUI Programming model. 6

The ASPplus Solutions Compan

Design Goals • To make ABAP Objects as simple as possible. • To use only proven OO concepts. • To comply with external standards whenever possible (for example, to allow mapping to COM, CORBA, and UML).

7

The ASPplus Solutions Compan

Continued... • To require much stronger typing (type checking) than traditional ABAP, where type specification is almost always optional.

8

The ASPplus Solutions Compan

Elements Of ABAP Objects • • • • •

9

Classes Interfaces Objects Object References Inheritance

The ASPplus Solutions Compan

Classes

10

• Classes are the central element of objectorientation • A class describes a general element or a general concept, for example the abstract concepts Business Partner, Material, Transaction, Equipment or list. • You can define classes globally using the class builder (Transaction SE24) or locally in an ABAP program. • All of the ABAP programs can access the global classes. • Local classes and interfaces can only be used in The ASP Solutions Compan the program in which they are defined. plus

Components of classes • • • •

11

Attributes Methods Events Types and Constants

The ASPplus Solutions Compan

Continued… •

In ABAP Objects classes are made up of a definition and an implementation part. • Example CLASS C1_PARTY DEFINITION. ENDCLASS. CLASS C1_PARTY IMPLEMETAION. ENDCLASS. 12

The ASPplus Solutions Compan

Attributes • Attributes can take on values within an object at runtime. The sum of all attributes and values describes the state of an object. • Attributes can be of two types 3. Static attributes 4. Instance attributes 13

The ASPplus Solutions Compan

Instance Attributes • Instance attributes represents the instancedependent status of an object. Instance attributes are declared using the statement DATA

14

The ASPplus Solutions Compan

Static Attributes • Static attributes represents the instanceindependent status of the class, which applies to all instances. Static attributes exist once for each class. They are declared using the statement CLASSDATA and are retained for the entire runtime. 15

The ASPplus Solutions Compan

Example Class C1_party DEFINITION. PUBLIC SECTION. CLASS-DATA : instance_count type I. DATA : name(50) type C. ENDCLASS.

16

The ASPplus Solutions Compan

Methods • Methods describe the behavior of objects within a class. • They could be compared to the subroutine in normal ABAP • They can access all attributes of their class and can thus change the status of an object. 17

The ASPplus Solutions Compan

Continued… • Again Methods are of two type Static Methods Instance Methods • Special Method : Constructor

18

The ASPplus Solutions Compan

Methods • An instance method is declared using the statement METHODS. It can access all attributes of a class and trigger all events of the class. • Static method is declared using the statement CLASS-METHODS. It can access static attributes and trigger only static events. 19

The ASPplus Solutions Compan

Methods • Methods can have any number of IMPORTING parameters and one RETURNING parameter. • In addition to the regular methods, there are special methods called CONSTRUCTOR and CLASS_CONSTRUCTOR, which are called implicitly when objects are generated or when class components are called for the first time.

20

The ASPplus Solutions Compan

Example Types : Boolean(1) type c, Pname(50) type c. CLASS C1_party DEFINITION. PUBLIC SECTION. CLASS-METHODS : is_class_with_objects RETURNING VALUE(re_bool) TYPE bollean. METHODS : change_name IMPORTING value (im_new_name) TYPE pname. ENDCLASS 21

The ASPplus Solutions Compan

Events • Events enable objects or classes to trigger event handler methods in other objects or classes. They are declared in the declaration part of a class and raised in its methods. • They are of two types Instance Events Static Events 22

The ASPplus Solutions Compan

Continued… • You can declare events by using the statements EVENTS for instance events and CLASS-EVENTS for static events. • Instance events can be raised in any method of the declaring class, whereas static events can only be raised in static methods. 23

The ASPplus Solutions Compan

Example

24

Class ship DEFINITION. PUBLIC SECTION. METHODS DRIVE. EVENTS emergency_call. ENCLASS. CLASS ship IMPLEMENTATION. METHOD DRIVE. if speed > more_speed. RAISE EVENT emergency_call. Endif. ENDMETHOD. The ASP Solutions Compan plus

Types and Constants. • The statements TYPES can be used to declare self-defined ABAP data types within a class. • Constants are specific static attributes whose values are defined in the declaration and cannot be changed. Constants, are not instance-dependent and exist ones for all objects of a class. 25

The ASPplus Solutions Compan

Interface • The Interface concept describes a class interface. You can define the same components in an interface that you can in classes, however without implementing them. • Classes can implement interfaces, and subsequently be addressed via these interfaces. For example, a class cl_class can implement the interface if_archive and thereby become archivable, or it can implement if_workflow and thereby take part in a workflow. 26

The ASPplus Solutions Compan

Nested Interfaces • By using the INTERFACES statement within the interface definition, you can define nested interfaces.

27

The ASPplus Solutions Compan

Interface References • A class which implements a specific interface can be addressed via this interface reference. Using such an interface reference, you can access the components defined in the interface. In this way a user can view different classes through the 'spectacles' of an interface and address them in a uniform manner. (DATA: reference TYPE REF TO cl_interface). 28

The ASPplus Solutions Compan

Inheritance • Inheritance allows you to define classes by deriving them from existing classes. The new class adopts or inherits all components of the existing class. The existing class is called a super class of the new class. • A class can have any number of direct subclasses, but only one super class. ABAP Objects thus uses single inheritance. 29

The ASPplus Solutions Compan

Objects • Objects are instance of classes. All transient objects exist within the context of an internal session (memory area of an ABAP program). You can create any number of objects(instances) for a class. Each one has a unique identity and its own attributes. • An object remains intact for as long as it is used in a program. 30

The ASPplus Solutions Compan

Object References • Object references are used as pointer to objects. Object references (the value of reference variables) are the only way to access component of an object in an ABAP program.You can use references to access attributes and methods, but not events. 31

The ASPplus Solutions Compan

THANK YOU

32

The ASPplus Solutions Compan

Related Documents

Introducing Abap Objects
November 2019 28
Introducing Abap Objects
November 2019 23
Abap Objects
November 2019 52
Exercise 5 - Abap Objects
November 2019 35
Abap Objects Program
November 2019 26
Sap Html Viewer Abap Objects
November 2019 26