Entering content frameClasses - Introductory Example  Locate the document in its SAP Library structure

Von Funktionsgruppen zu Objekten

The following simple example uses ABAP Objects to program a counter. For comparison, see also the example in From Function Groups to Objects

Example

CLASS C_COUNTER DEFINITION.

  PUBLIC SECTION.
    METHODS: SET_COUNTER IMPORTING VALUE(SET_VALUE) TYPE I,
             INCREMENT_COUNTER,
             GET_COUNTER EXPORTING VALUE(GET_VALUE) TYPE I.

  PRIVATE SECTION.
    DATA COUNT TYPE I.

ENDCLASS.

CLASS C_COUNTER IMPLEMENTATION.

  METHOD SET_COUNTER.
    COUNT = SET_VALUE.
  ENDMETHOD.

  METHOD INCREMENT_COUNTER.
    ADD 1 TO COUNT.
  ENDMETHOD.

  METHOD GET_COUNTER.
    GET_VALUE = COUNT.
  ENDMETHOD.

ENDCLASS.

The class C_COUNTER contains three public methods - SET_COUNTER, INCREMENT_COUNTER, and GET_COUNTER. Each of these works with the private integer field COUNT. Two of the methods have input and output parameters. These form the data interface of the class. The field COUNT is not outwardly visible.

The example in the section Working with Objects shows how you can create instances of the class C_COUNTER.

 

 

 

 

 

Leaving content frame