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.
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.