SAP ABAP - Objects | Learn and Master SAP ABAP - Software Development PDF Download

Introduction

  • 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 −

  • Has a state.
  • Has a unique identity.
  • May or may not display the behavior.

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 −

  • Creating a reference variable with reference to the class. The syntax for which is −

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

  • Creating an object from the reference variable. The syntax for which is −

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.

The document SAP ABAP - Objects | Learn and Master SAP ABAP - Software Development is a part of the Software Development Course Learn and Master SAP ABAP.
All you need of Software Development at this link: Software Development
73 videos|68 docs

Top Courses for Software Development

FAQs on SAP ABAP - Objects - Learn and Master SAP ABAP - Software Development

1. What is Object-Oriented Programming in SAP ABAP?
Ans. Object-Oriented Programming in SAP ABAP is a programming paradigm that uses objects to design applications. It allows developers to create reusable code components that can be easily maintained and extended.
2. How do you create an object in SAP ABAP?
Ans. To create an object in SAP ABAP, you first need to define a class using the CLASS statement. Then, you can create an instance of the class using the CREATE OBJECT statement.
3. What are the benefits of using Objects in SAP ABAP?
Ans. Using Objects in SAP ABAP allows for better code organization, reusability, and maintainability. It also enables developers to implement encapsulation, inheritance, and polymorphism in their programs.
4. How can you implement inheritance in SAP ABAP Objects?
Ans. Inheritance in SAP ABAP Objects can be implemented by using the EXTENDS keyword in the class definition. This allows a subclass to inherit the attributes and methods of a superclass.
5. Can you explain the concept of polymorphism in SAP ABAP Objects?
Ans. Polymorphism in SAP ABAP Objects allows objects of different classes to be treated as objects of a common superclass. This enables the same method to be called on different objects, resulting in different behaviors based on the object's specific class.
73 videos|68 docs
Download as PDF
Explore Courses for Software Development exam

Top Courses for Software Development

Signup for Free!
Signup to see your scores go up within 7 days! Learn & Practice with 1000+ FREE Notes, Videos & Tests.
10M+ students study on EduRev
Related Searches

SAP ABAP - Objects | Learn and Master SAP ABAP - Software Development

,

shortcuts and tricks

,

mock tests for examination

,

Sample Paper

,

MCQs

,

Semester Notes

,

SAP ABAP - Objects | Learn and Master SAP ABAP - Software Development

,

practice quizzes

,

Viva Questions

,

pdf

,

Free

,

Important questions

,

study material

,

ppt

,

Summary

,

Extra Questions

,

past year papers

,

Exam

,

SAP ABAP - Objects | Learn and Master SAP ABAP - Software Development

,

Previous Year Questions with Solutions

,

Objective type Questions

,

video lectures

;