Visibility Section in Classes | SAP ABAP
Last Updated :
23 Jul, 2025
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.
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:
Public Section in SAP ABAP
Components declared as public are accessible from anywhere, both within the class and from external programs or classes. This means they can be used by other classes or objects, making them part of the public interface of the class.
CLASS <class_name> DEFINITION.
PUBLIC SECTION.
" Define public attributes and methods.
ENDCLASS.
Protected Section in SAP ABAP:
Components declared as protected are similar to private components, but with an additional level of access. They are accessible from the same class and its subclasses (inheritors), but not from external programs or classes. Protected components are used when you want to provide access to subclasses but still keep them hidden from external code.
CLASS <class_name> DEFINITION.
PROTECTED SECTION.
" Define protected attributes and methods.
ENDCLASS.
Private Section in SAP ABAP:
Components declared as private are only accessible within the same class. They are not visible or accessible from external programs or classes. Private components are used to encapsulate the internal details of a class and are not part of the class's public interface.
CLASS <class_name> DEFINITION.
PRIVATE SECTION.
" Define private attributes and methods.
ENDCLASS.
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.
Related posts:
Similar Reads
SAP Advanced Business Application Programming (ABAP) SAP ABAP stands for Advanced Business Application Programming. 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 i
6 min read
What is SAP ABAP: A Brief Overview 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 bu
8 min read
SAP ABAP | Basic Syntax & Statements The German software company SAP created the high-level programming language, ABAP (Advanced Business Application Programming) primarily, this language serves as a tool for developing applications within the SAP R/3 system. Designed with simplicity and ease of learning in mind, ABAP syntax allows eff
9 min read
SAP ABAP | Understanding Variables What is a Variable?Variable are named data objects that refer to the memory location allocated during the program execution for processing. As the name indicates, users can use refer to the range of values that may be stored inside and the range of actions that can be carried out on the variable.Syn
7 min read
SAP ABAP Keywords The core of many global enterprises, SAP ABAP stands for Advanced Business Application Programming. It is the heart and soul of SAP systems. It gives users the ability to expand and modify SAP apps to satisfy particular business needs. The fundamental building blocks of SAP ABAP are its keywords, wh
5 min read
SAP ABAP | Constants & Literals Explained In the world of SAP ABAP (Advanced Business Application Programming), the use of Constants and Literals is necessary for the effective handling of data. Literals are used to denote specific data types such as numbers, characters, strings, and boolean values.Constants & Literals in SAPWhat are Li
7 min read
SAP ABAP | Data Types Before Understanding the Data type first understand the Data object. Data objects are variables that we declare in the program. It occupies some memory where you can store the data from external sources. Data can be of different types, so data types are responsible for defining the type of data of t
6 min read
Relational operators in SAP ABAP Relational operators in SAP ABAP are symbols or combinations of symbols that compare values and return a Boolean result (either true or false). These operators allow developers to establish relationships between variables, constants, or expressions, facilitating decision-making processes in the prog
6 min read
Operators in SAP ABAP High-level programming languages like SAP ABAP (Advanced Business Application Programming) are used to create apps in the SAP environment. Operators are essential for the execution of many different operations in SAP ABAP, ranging from straightforward arithmetic computations to complex logical analy
7 min read
Loop concept in SAP ABAP