Attributes in SAP ABAP Classes
Within a class in SAP ABAP, attributes serve as variables, they hold data and state information. We can classify these attributes into two types:
- instance attributes
- static attributes.
Instance Attributes in SAP ABAP
Specific to each object or instance of the class, instance attributes uniquely hold values for every object instance, thus permitting diverse objects to preserve separate states. When creating an object of the class, initialization occurs automatically enabling access and modification through its respective object instance, this is where these unique characteristics become operative.
CLASS lcl_class_definition DEFINITION.
PUBLIC SECTION.
DATA: instance_attribute TYPE data_type.
ENDCLASS.
In the example above, instance_attribute is an instance attribute that holds a specific value for each object of the class lcl_class_definition.
Static Attributes in SAP ABAP
All instances of the class share static attributes. Throughout the entire execution of the program, these attributes maintain their value and any modifications made to them impact all instances simultaneously. Sharing a value across all class instances is particularly useful for these specific attributes.
CLASS lcl_class_definition DEFINITION.
PUBLIC SECTION.
CLASS-DATA static_attribute TYPE data_type.
ENDCLASS.
In this case, static_attribute is a static attribute that is shared among all instances of the class lcl_class_definition.
Classes in 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.
Table of Content
- Introduction to Classes in SAP ABAP
- Syntax for defining a class in SAP ABAP
- Syntax for implementing a class in SAP ABAP
- Attributes in SAP ABAP Classes
- Methods in SAP ABAP Classes
- Accessing Attributes and Methods in SAP ABAP:
- Static Attributes
- Constructors in SAP ABAP
- ME operator in methods
- Examples of Classes in SAP ABAP