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 function modules are called.

Other versions: 7.31 | 7.40 | 7.54

Source Code

    DATA: itab TYPE spfli_tab,
          jtab TYPE spfli_tab.

    DATA carrier TYPE s_carr_id VALUE 'LH'.
    cl_demo_input=>request( CHANGING field = carrier ).

    DATA(out) = cl_demo_output=>new( ).

    CALL FUNCTION 'READ_SPFLI_INTO_TABLE'
      EXPORTING
        id        = carrier
      IMPORTING
        itab      = itab
      EXCEPTIONS
        not_found = 4.
    IF sy-subrc <> 0.
      MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
              INTO DATA(msg).
      out->write( msg ).
    ENDIF.

    TRY.
        CALL FUNCTION 'READ_SPFLI_INTO_TABLE_NEW'
          EXPORTING
            id   = carrier
          IMPORTING
            itab = jtab.
      CATCH cx_no_flight_found INTO DATA(exc).
        out->write( exc->get_text( ) ).
    ENDTRY.

    ASSERT itab = jtab.
    out->display( itab ).

Description

The function modules READ_SPFLI_INTO_TABLE and READ_SPFLI_INTO_TABLE_NEW read all data from the database table SPFLI where the key field CARRID matches the import parameter id and passes this data to the internal tables itab or jtab. If no suitable data can be found, exceptions are raised.

  • In READ_SPFLI_INTO_TABLE, the non-class-based exception NOT_FOUND is triggered by MESSAGE ... RAISING.
  • In READ_SPFLI_INTO_TABLE_NEW, the class-based exception is triggered CX_NO_FLIGHT_FOUND byRAISE EXCEPTION ... MESSAGE. CX_NO_FLIGHT_FOUND implements the interface IF_T100_DYN_MSG.

Otherwise, the table is passed to the caller as an export parameter.

The actual parameters carrier and itab or itab have the same data types as the corresponding interface parameters of the function module. The exceptions are handled. The relevant exception text is accessed in different ways.

  • With the non-class-based exception, the text is implicitly available via system fields.
  • With the class-based exception, the text is specified by attributes of the exception object.