Ads

All about Classes in ABAP Object Oriented Programming

All about Classes in ABAP Object Oriented Programming

Class describes real world Object that may be car ,home and Animal .In ABAP Object Oriented (OO)Programming ,Class concept is first and Fore most Topic ,so through this post ,we will learn class in ABAP and Types of class and How to create classes and Methods in SAP ABAP.


Class consists the Properties and Attributes.
Properties are Methods or Functions or Procedures.
Attributes are Variables .

One class can have Any number of Objects that is Object is like a class but object can never be a Class.

Example :Car is a class ,Here class contains some common Properties for its related Objects.
                Object may be different companies like Ford Maruthi etc.

Objects are instances of a class ,so for one class ,we can create many objects 

Class Definition in SAP ABAP

Class: we can build an Object properties using class.
The attributes of objects are defined by the components of the class, which describe the state and behavior of Objects.

Local and Global Classes

Classes in ABAP Objects can be declared either globally or locally. You define global classes and interfaces in the Class Builder (Transaction SE24) in the ABAP Workbench.

Local Classes are Custom Classes which created by us to use it in our Local Program which starts with the X or Y ,These classes are created in class Builder.

 Creating Local Classes

 Class Definition  contains the declaration for all components (attributes, methods, events) of the class.
CLASS class DEFINITION. 
...
ENDCLASS.

The implementation part of a class contains the implementation of all methods of the class. 

CLASS class IMPLEMENTATION.
...
ENDCLASS.

Class Functionality
 A class contains components
Each component is assigned to a visibility section
Classes implement methods

Class Elements:

 All components are declared in the declaration part of the class. 
Attributes
Attributes are internal data fields within a class that can have any ABAP data type.

Instance Attributes
The contents of instance attributes define the instance-specific state of an object. You declare them using the DATA statement.
Static Attributes
The contents of static attributes define the state of the class that is valid for all instances of the class. Static attributes exist once for each class. You declare them using the CLASS-DATA statement.

Methods
Methods are internal Functions in a class that define the behavior of an object. They can access all of the attributes of a class.

METHOD meth.
...
ENDMETHOD.

Instance Methods
You declare instance methods using the METHODSstatement. They can access all of the attributes of a class, and can trigger all of the events of the class.

Static Methods
You declare static methods using the CLASS-METHODS statement. They can only access static attributes and trigger static events.

Special Methods
As well as normal methods, which you call using CALL METHOD, there are two special methods called constructor and class_constructor that are automatically called when you create an object or when you first access the components of a class.

Events
Objects or classes can use events to trigger event handler methods in other objects or classes.

Instance Events
You declare instance events using the EVENTSstatement. An instance event can only be triggered in an instance method.
Static Events
You declare static events using the CLASS-EVENTSstatement. 

Types
You can define your own ABAP data types within a class using the TYPESstatement.


Visibility Sections or Access Specifiers
You can divide the declaration part of a class into up to three visibility areas:
CLASS class DEFINITION. 
 PUBLIC SECTION.
...
 PROTECTED SECTION.
...
 PRIVATE SECTION.
...
ENDCLASS.

Public Section
All of the components declared in the public section are accessible to all users of the class.

Protected Section
All of the components declared in the protected section are accessible to all methods of the class and of classes that inherit from it.

Private Section
Components that you declare in the private section are only visible in the methods of the same class.

Classes with Non-Public Instantiation
Using the statement
CLASS class DEFINITON CREATE PROTECTED|PRIVATE.

If you learn Object Oriented Programming ,there is more choice to select for interview among ABAP peers.

Step by Step Tutorial for creating Class in Class Builder

Comments

Popular posts from this blog

BADI Interview Questions in SAP ABAP

Sample SAP ABAP Programming Examples for Practice

Module Pool Programming Interview Questions and Answers in SAP ABAP

Step by Step tutorial on BDC Session Method Program in SAP ABAP

SAP ABAP Interview Questions and Answers for 10 Years Experienced