Object Oriented ABAP Local Class Instance Methods Static Methods Functional Methods

In this article we will discuss about Object Oriented ABAP Local Class Instance Methods, Static Methods and Functional Methods with the help of an example. Here you learn

  • Object Oriented ABAP Local Class Methods syntax
  • Object Oriented ABAP Instance Methods
  • Object Oriented ABAP Static Methods
  • Object Oriented ABAP Functional Methods
  • Access static attributes
  • Access Instance attributes
  • Attribute with READ-ONLY addition

Method Signature

Both instance and static methods can have IMPORTING, EXPORTING, CHANGING and RETURNING parameters.

METHODS <method name> 
        [ IMPORTING <iv> TYPE <typename>
          EXPORTING <ev> TYPE <typename>
          CHANGING <cv> TYPE <typename>
          RETURNING VALUE(<rv>) TYPE <typename>
          EXCEPTIONS <exception>
          RAISNING <exception_class>].

Use VALUE addition to make a parameter pass-by-value. Use OPTIONAL or DEFAULT addition to make a parameter optional. A method with a RETURNING parameter is called a Functional method.

In a class, you can define both static and instance methods. An instance method can access both instance and static components whereas a static method can access only static components.

Syntax to call Instance and Static methods

"to call instance method you need an instance of the class
CALL METHOD obj_ref->methodname 

"to call static method using class name
class_name=>methodname "

With SAP NW AS 6.10, CALL METHOD keyword is optional when calling a method.

Object Oriented ABAP Class Implementation example

Class Definition

Class Implementation

Creating Object

Output of the program: