The following simple example uses ABAP Objects to program a counter. For comparison, see also the example in From Function Groups to Objects
CLASS counter DEFINITION.
PUBLIC SECTION.
METHODS: set IMPORTING
value(set_value) TYPE i,
increment,
get
EXPORTING value(get_value) TYPE i.
PRIVATE SECTION.
DATA count TYPE i.
ENDCLASS.
CLASS counter IMPLEMENTATION.
METHOD set.
count =
set_value.
ENDMETHOD.
METHOD increment.
ADD 1 TO
count.
ENDMETHOD.
METHOD get.
get_value =
count.
ENDMETHOD.
ENDCLASS.
The class counter contains three public methods set, increment, and get. 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 counter.