Example of Classes in SAP ABAP

REPORT demo_class_usage.

CLASS demo_class DEFINITION.
PUBLIC SECTION.
METHODS:
display_name.
PRIVATE SECTION.
DATA:
name TYPE string.
ENDCLASS.

CLASS demo_class IMPLEMENTATION.
METHOD display_name.
WRITE: / 'Name:', name.
ENDMETHOD.
ENDCLASS.

START-OF-SELECTION.

DATA: obj TYPE REF TO demo_class.
CREATE OBJECT obj.
obj->name = 'John Doe'.
obj->display_name( ).

Output:

Name: John Doe

You use these access modifiers to control the visibility and access to the various parts of your class. By doing so, you can maintain the encapsulation of your class’s internal logic and provide a well-defined public interface for other parts of your ABAP program or other classes. This is a fundamental principle of object-oriented programming that helps improve code organization, reusability, and maintainability.

Visibility Section in Classes | SAP ABAP

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.

Similar Reads

Introduction to Classes in SAP ABAP

A class is a blueprint or template in SAP ABAP, a class defines the properties and behavior of objects. it encapsulates data – including the methods that act on this data. This encapsulation allows for modular code structures. reusable entities can be created with ease. Implementing various Object-Oriented Programming (OOP) concepts in SAP ABAP such as encapsulation, inheritance, and polymorphism on classes functioning as their foundation. Developers can create complex, structured applications through their use of these tools. this process not only facilitates superior code management but also enhances reusability....

Visibility Sections in SAP ABAP

In SAP ABAP (Advanced Business Application Programming), like in many other programming languages, you can control the visibility and accessibility of class components (attributes, methods, and events) using access modifiers, including public, private, and protected. These access modifiers determine where and how the class components can be accessed. Here’s an explanation of each:...

Example of Classes in SAP ABAP:

REPORT demo_class_usage.CLASS demo_class DEFINITION. PUBLIC SECTION. METHODS: display_name. PRIVATE SECTION. DATA: name TYPE string.ENDCLASS.CLASS demo_class IMPLEMENTATION. METHOD display_name. WRITE: / 'Name:', name. ENDMETHOD.ENDCLASS.START-OF-SELECTION.DATA: obj TYPE REF TO demo_class.CREATE OBJECT obj.obj->name = 'John Doe'.obj->display_name( )....

Related posts:

SAP ABAP | Object Orientation Classes in SAP ABAP SAP ABAP | Understanding Inheritance Abstract Class Vs Interface in SAP ABAP SAP ABAP | Interfaces Nested Loop in SAP ABAP Operators in SAP ABAP Top SAP ABAP Interview Questions for Freshers SAP ABAP Keywords How Does SAP Work?...