Show TOC

Instances of Function Groups: ExampleLocate this document in the navigation structure

The following example shows the object-oriented aspect of function groups in the simple case of a counter.

Tip

Suppose we have a function group called counter:

FUNCTION-POOL counter.

DATA count TYPE i.

FUNCTION set_counter.* Local Interface IMPORTING VALUE(SET_VALUE)  count = set_value.ENDFUNCTION.

FUNCTION increment_counter.  ADD 1 TO count.ENDFUNCTION.

FUNCTION get_counter.* Local Interface: EXPORTING VALUE(GET_VALUE)  get_value = count.ENDFUNCTION.

The function group counter is used as a counter. It has a global integer field count, and three function modules, set_counter, increment_counter, and get_counter, that work with the field. Two of the function modules have input and output parameters. These form the data interface of the function group. From on object-oriented point of view, a function gorup has exclusively private attributes and public methods.

Any ABAP program can then work with this function group. For example:

REPORT demo_function_group_counter.

DATA number TYPE i VALUE 5.

CALL FUNCTION 'SET_COUNTER'     EXPORTING          set_value = number.

DO 3 TIMES.  CALL FUNCTION 'INCREMENT_COUNTER'.  ENDDO.

CALL FUNCTION 'GET_COUNTER'     IMPORTING          get_value = number.

WRITE number.

After this section of the program has been processed, the program variable number will have the value 8.

The program itself cannot access the count field in the function group. Operations on this field are fully encapsulated in the function module. The program can only communicate with the function group by calling its function modules.