Blake's SAP ABAP 37-52 Document

SAP PM Prerequisite Modules - Navigational Tutorial and Resources Links
Module Module Name Links Links Blake's Links
PM Plant Mantenance tutorials point   Blake
MM Material Management tutorials point Overview Guru99 Blake: 1-10 | 11-20 | 21-25
SD Sales and Distribution tutorials point Tutorial Guru99 Blake
PP Production Planning tutorials point Tutorial Guru99 Blake | 1-7
External Links
Google NewLanguage.html  FICO Module: Blake's 1-28 29-56 57-66 67-83 : Tutorials Point
  Download Info  ABAP Module: Blake's  1-18  19-36  37-52       : Tutorials Point

 

SAP ABAP (Advanced Business Application Programming) - ABAP Tutorial and ABAP Resources
1 Home ABAP_Doc     Tutorials Point   19 Tables ABAP_Doc     Tutorials Point   37 Object Orientation ABAP_Doc     Tutorials Point
2 Overview ABAP_Doc     Tutorials Point   20 Structures ABAP_Doc     Tutorials Point   38 Objects ABAP_Doc     Tutorials Point
3 Environment ABAP_Doc     Tutorials Point   21 Views ABAP_Doc     Tutorials Point   39 Classes ABAP_Doc     Tutorials Point
4 Screen Navigation ABAP_Doc     Tutorials Point   22 Search Help ABAP_Doc     Tutorials Point   40 Inheritance ABAP_Doc     Tutorials Point
5 Basic Syntax ABAP_Doc     Tutorials Point   23 Lock Objects ABAP_Doc     Tutorials Point   41 Polymorphism ABAP_Doc     Tutorials Point
6 Data Types ABAP_Doc     Tutorials Point   24 Modularization ABAP_Doc     Tutorials Point   42 Encapsulation ABAP_Doc     Tutorials Point
7 Variables ABAP_Doc     Tutorials Point   25 Subroutines ABAP_Doc     Tutorials Point   43 Interfaces ABAP_Doc     Tutorials Point
8 Constants & Literals ABAP_Doc     Tutorials Point   26 Macros ABAP_Doc     Tutorials Point   44 Object Events ABAP_Doc     Tutorials Point
9 Operators ABAP_Doc     Tutorials Point   27 Function Modules ABAP_Doc     Tutorials Point   45 Report Programming ABAP_Doc     Tutorials Point
10 Loop Control ABAP_Doc     Tutorials Point   28 Include Programs ABAP_Doc     Tutorials Point   46 Dialog Programming ABAP_Doc     Tutorials Point
11 Decisions ABAP_Doc     Tutorials Point   29 Open SQL Overview ABAP_Doc     Tutorials Point   47 Smart Forms ABAP_Doc     Tutorials Point
12 Strings ABAP_Doc     Tutorials Point   30 Native SQL Overview ABAP_Doc     Tutorials Point   48 SAPscripts ABAP_Doc     Tutorials Point
13 Date & Time ABAP_Doc     Tutorials Point   31 Internal Tables ABAP_Doc     Tutorials Point   49 Customer Exits ABAP_Doc     Tutorials Point
14 Formatting Data ABAP_Doc     Tutorials Point   32 Creating Internal Tables ABAP_Doc     Tutorials Point   50 User Exits ABAP_Doc     Tutorials Point
15 Exception Handling ABAP_Doc     Tutorials Point   33 Populating Internal Tables ABAP_Doc     Tutorials Point   51 Business Add-Ins ABAP_Doc     Tutorials Point
16 Dictionary ABAP_Doc     Tutorials Point   34 Copying Internal Tables ABAP_Doc     Tutorials Point   52 SAP ABAP - Web Dynpro ABAP_Doc     Tutorials Point
17 Domains ABAP_Doc     Tutorials Point   35 Reading Internal Tables ABAP_Doc     Tutorials Point        
18 Data Elements ABAP_Doc     Tutorials Point   36 Deleting Internal Tables ABAP_Doc     Tutorials Point        


(37) SAP ABAP - Object Orientation

Object orientation simplifies software design to make it easier to understand, maintain, and reuse. Object Oriented Programming (OOP) represents a different way of thinking in writing software. The beauty of OOP lies in its simplicity. The expressiveness of OOP makes it easier to deliver quality software components on time.

As solutions are designed in terms of real-world objects, it becomes much easier for programmers and business analysts to exchange ideas and information about a design that uses a common domain language. These improvements in communication help to reveal hidden requirements, identify risks, and improve the quality of software being developed. The object-oriented approach focuses on objects that represent abstract or concrete things of the real world. These objects are defined by their character and properties that are represented by their internal structure and their attributes (data). The behavior of these objects is described by methods (i.e. functionality).

Let’s compare the procedural and object oriented programming −

Features Procedure Oriented approach Object Oriented approach
Emphasis Emphasis is on tasks. Emphasis is on things that does those tasks.
Modularization Programs can be divided into smaller programs known as functions. Programs are organized into classes and objects and the functionalities are embedded into methods of a class.
Data security Most of the functions share global data. Data can be hidden and can’t be accessed by external sources.
Extensibility This is more time consuming to modify and extend the existing functionality. New data and functions can be added effortlessly as and when required.

ABAP was initially developed as a procedural language (just similar to earlier procedural programming language like COBOL). But ABAP has now adapted the principles of object oriented paradigms with the introduction of ABAP Objects. The object-oriented concepts in ABAP such as class, object, inheritance, and polymorphism, are essentially the same as those of other modern object-oriented languages such as Java or C++.

As object orientation begins to take shape, each class assumes specific role assignments. This division of labor helps to simplify the overall programming model, allowing each class to specialize in solving a particular piece of the problem at hand. Such classes have high cohesion and the operations of each class are closely related in some intuitive way.

The key features of object orientation are −


(38) SAP ABAP - Objects

An object is a special kind of variable that has distinct characteristics and behaviors. The characteristics or attributes of an object are used to describe the state of an object, and behaviors or methods represent the actions performed by an object.

An object is a pattern or instance of a class. It represents a real-world entity such as a person or a programming entity like variables and constants. For example, accounts and students are examples of real-world entities. But hardware and software components of a computer are examples of programming entities.

An object has the following three main characteristics −

The state of an object can be described as a set of attributes and their values. For example, a bank account has a set of attributes such as Account Number, Name, Account Type, Balance, and values of all these attributes. The behavior of an object refers to the changes that occur in its attributes over a period of time.

Each object has a unique identity that can be used to distinguish it from other objects. Two objects may exhibit the same behavior and they may or may not have the same state, but they never have the same identity. Two persons may have the same name, age, and gender but they are not identical. Similarly, the identity of an object will never change throughout its lifetime.

Objects can interact with one another by sending messages. Objects contain data and code to manipulate the data. An object can also be used as a user-defined data type with the help of a class. Objects are also called variables of the type class. After defining a class, you can create any number of objects belonging to that class. Each object is associated with the data of the type class with which it has been created.

Creating an Object

The object creation usually includes the following steps −

DATA: <object_name> TYPE REF TO <class_name>. 
CREATE Object: <object_name>. 

Example

REPORT ZDEMO_OBJECT.  CLASS Class1 Definition.  Public Section.  DATA: text1(45) VALUE 'ABAP Objects.'.  METHODS: Display1.  ENDCLASS.   CLASS Class1 Implementation.  METHOD Display1.  Write:/ 'This is the Display method.'.  ENDMETHOD.  ENDCLASS.   START-OF-SELECTION.  DATA: Class1 TYPE REF TO Class1.  CREATE Object: Class1.  Write:/ Class1->text1.  CALL METHOD: Class1->Display1.

The above code produces the following output −

ABAP Objects.  This is the Display method.

(39) SAP ABAP - Classes

A class is used to specify the form of an object and it combines data representation and methods for manipulating that data into one neat package. The data and functions within a class are called members of the class.

Class Definition and Implementation

When you define a class, you define a blueprint for a data type. This doesn't actually define any data, but it does define what the class name means, what an object of the class will consist of, and what operations can be performed on such an object. That is, it defines the abstract characteristics of an object, such as attributes, fields, and properties.

The following syntax shows how to define a class −

CLASS <class_name> DEFINITION.  ..........  ..........  ENDCLASS. 

A class definition starts with the keyword CLASS followed by the class name, DEFINITION and the class body. The definition of a class can contain various components of the class such as attributes, methods, and events. When we declare a method in the class declaration, the method implementation must be included in the class implementation. The following syntax shows how to implement a class −


(40) SAP ABAP - Inheritance

One of the most important concepts in object oriented programming is that of inheritance. Inheritance allows us to define a class in terms of another class, which makes it easier to create and maintain an application. This also provides an opportunity to reuse the code functionality and fast implementation time.

When creating a class, instead of writing completely new data members and methods, the programmer can designate that the new class should inherit the members of an existing class. This existing class is called the base class or super class, and the new class is referred to as the derived class or sub class.

The inheritance relationship is specified using the ‘INHERITING FROM’ addition to the class definition statement.

Following is the syntax −


(41) SAP ABAP - Polymorphism

The term polymorphism literally means ‘many forms’. From an object-oriented perspective, polymorphism works in conjunction with inheritance to make it possible for various types within an inheritance tree to be used interchangeably. That is, polymorphism occurs when there is a hierarchy of classes and they are related by inheritance. ABAP polymorphism means that a call to a method will cause a different method to be executed depending on the type of object that invokes the method.

The following program contains an abstract class 'class_prgm', 2 sub classes (class_procedural and class_OO), and a test driver class 'class_type_approach'. In this implementation, the class method 'start' allow us to display the type of programming and its approach. If you look closely at the signature of method 'start', you will observe that it receives an importing parameter of type class_prgm. However, in the Start-Of-Selection event, this method has been called at run-time with objects of type class_procedural and class_OO.


(42) SAP ABAP - Encapsulation

Encapsulation is an Object Oriented Programming (OOP) concept that binds together data and functions that manipulate the data, and keeps both safe from outside interference and misuse. Data encapsulation led to the important OOP concept of data hiding. Encapsulation is a mechanism of bundling the data and the functions that use them, and data abstraction is a mechanism of exposing only the interfaces and hiding the implementation details from the user.

ABAP supports the properties of encapsulation and data hiding through the creation of user-defined types called classes. As discussed earlier, a class can contain private, protected and public members. By default, all items defined in a class are private.

Encapsulation by Interface

Encapsulation actually means one attribute and method could be modified in different classes. Hence data and method can have different form and logic that can be hidden to separate class.

Let's consider encapsulation by interface. Interface is used when we need to create one method with different functionality in different classes. Here the name of the method need not be changed. The same method will have to be implemented in different class implementations.

Example

The following program contains an Interface inter_1. We have declared attribute and a method method1. We have also defined two classes like Class1 and Class2. So we have to implement the method ‘method1’ in both of the class implementations. We have implemented the method ‘method1’ differently in different classes. In the start-ofselection, we create two objects Object1 and Object2 for two classes. Then, we call the method by different objects to get the function declared in separate classes.


(43) SAP ABAP - Interfaces

paragraph


(44) SAP ABAP - Object Events

paragraph


(45) SAP ABAP - Report Programming


(46) SAP ABAP - Dialog Programming

paragraph


(47) SAP ABAP - Smart Forms

paragraph


(48) SAP ABAP - SAPscripts

paragraph


(49) SAP ABAP - Customer Exits


(50) SAP ABAP - User Exits

paragraph


(51) SAP ABAP - Business Add-Ins

paragraph


(52) SAP ABAP - Web Dynpro

paragraph



Reserve

paragraph