Open In App

SAP ABAP | Understanding Object

SAP ABAP (Advanced Business Application Programming) is a high-level programming language created by the German software company SAP SE. ABAP is primarily used for developing and customizing applications within the SAP ecosystem, which includes enterprise resource planning (ERP) systems and other business software solutions. C++ is used to implement the ABAP kernel. A procedural and object-oriented programming model are both supported by the hybrid programming language ABAP.

SAP ABAP | Understanding Object

What is an Object in SAP ABAP:

An object is a type of variable with unique traits and actions. An object’s features or attributes are used to describe its state, whereas behaviors or methods indicate the actions performed by an object in SAP ABAP. An object is a pattern or a class instance. It represents a physical entity, such as a person, or a programming entity, such as variables and constants. Accounts and students are two instances of real-world things. However, computer hardware and software are instances of programming entities.

Properties of Objects in SAP ABAP:



For efficient and flexible programming in SAP ABAP (Advanced Business Application Programming), an understanding of objects is essential. The foundation of the Object-Oriented Programming (OOP) paradigm is objects, which give code a means to be organized and structured.

Creating an Object in SAP ABAP:

The following steps are typically included in the production of an object:

Syntax:

REPORT ZDEMO_OBJECT. 
CLASS Class1 Definition.
Public Section.
DATA: text1(45) VALUE 'GFG SAP 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.

Output:

GFG SAP ABAP Objects
This is the Display method.

Example of Creating and Using an Object in SAP ABAP:

CLASS lcl_account DEFINITION.
PUBLIC SECTION.
DATA: account_number TYPE i,
balance TYPE f,
account_holder TYPE string.

METHODS: constructor,
deposit_balance IMPORTING amount TYPE f,
withdraw_balance IMPORTING amount TYPE f,
get_balance RETURNING VALUE(balance) TYPE f.
ENDCLASS.

CLASS lcl_account IMPLEMENTATION.
METHOD constructor.
" Initialize object attributes
ENDMETHOD.

METHOD deposit_balance.
" Add amount to the balance
ENDMETHOD.

METHOD withdraw_balance.
" Subtract amount from the balance
ENDMETHOD.

METHOD get_balance.
" Return the current balance
ENDMETHOD.
ENDCLASS.

DATA(account1) = NEW lcl_account( ).
account1->deposit_balance(1000.00).
WRITE: / 'Account Balance:', account1->get_balance( ).

Functionality of an Object in SAP ABAP:

Some Recent Articles Related to SAP ABAP OOPS concepts:

Conclusion:

Understanding objects in SAP ABAP is integral to building robust and efficient applications. Leveraging the OOP paradigm allows developers to create modular, scalable, and maintainable code, contributing to the overall success of SAP projects.


Article Tags :