Blog Archives

Links


Articles > SAP Basis > ABAP Objects > Objects implementation

Objects implementation

Once an object class has been defined through the declaration of its components, its methods may implemented. In fact, each method defined in the CLASS definition must have a corresponding implementation (ABSTRACT classes are an exception to this rule).

The implementation consists in coding the ABAP instructions that each method has to execute in order to provide its functionality.

Here is an example of possible coding for our minimal CLASS defining a business partner according to the very general definition given in a previous article about objects definition.

* Class definition

CLASS LCL_BUSINESS_PARTNER DEFINITION.
  PUBLIC SECTION.
    METHODS:
      m_SetName IMPORTING Name TYPE STRING,
      m_GetName RETURNING VALUE(Name) TYPE STRING,
      m_SetVAT IMPORTING VAT TYPE STRING,
      m_GetVAT RETURNING VALUE(VAT) TYPE STRING.

  PRIVATE SECTION.
    DATA:
      m_dSName TYPE STRING,
      m_dSVAT TYPE STRING.

ENDCLASS.

* Class implementation

CLASS LCL_BUSINESS_PARTNER IMPLEMENTATION.
  METHOD m_SetName.
    IF Name(1) CO SY-ABCDE AND STRLEN( Name ) > 5.
      m_dSName = Name.
    ENDIF.
  ENDMETHOD.

  METHOD m_GetName.
    Name = m_dSName.
  ENDMETHOD.

  METHOD m_SetVAT.
    m_dSVAT = VAT.
  ENDMETHOD.

  METHOD m_GetVAT.
    VAT = m_dSVAT.
  ENDMETHOD.
ENDCLASS.

The functionality implemented here is very basic as it simply aims at providing a set / get mechanism to enable a controlled value assignment of variables and to retrieve the variables values.

However it demonstrates the syntax of a class implementation. For the readers used to program with FORM subroutines in ABAP, a visible difference is the absence of formal parameters specification for the methods in the class implementation. These were mentioned in the class definition and are not repeated in the class implementation.