Skip to content

ABAP Keyword Documentation →  ABAP - Reference →  Calling and leaving program units →  Calling Processing Blocks →  Calling Procedures →  CALL FUNCTION →  CALL FUNCTION func 

Calling Function Modules

This example demonstrates how a function module is called.

Other versions: 7.31 | 7.40 | 7.54

Source Code

    DATA carrier TYPE s_carr_id VALUE 'LH'.

    DATA: itab TYPE spfli_tab,
          wa   LIKE LINE OF itab.

    cl_demo_input=>request( CHANGING field = carrier ).

        id        = carrier
        itab      = itab
        not_found = 1
        OTHERS    = 2.

    CASE sy-subrc.
      WHEN 1.
        MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                INTO DATA(msg).
        cl_demo_output=>display( msg ).
      WHEN 2.
          'Undefined error in function module' ).

    cl_demo_output=>display( itab ).


The function module READ_SPFLI_INTO_TABLE reads all data from the database table SPFLI where the key field CARRID matches the import parameter id and passes this data into the internal table itab. If no suitable data can be found, the exception NOT_FOUND is raised using MESSAGE ... RAISING. Otherwise, the table is passed to the caller as an export parameter.

The actual parameters carrier and itab in the program above have the same data types as the corresponding interface parameters of the function module. The exception NOT_FOUND is handled and the function module displays the same message text as if it were not handled.