SAP NetWeaver AS ABAP Release 740, ©Copyright 2014 SAP AG. All rights reserved.
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.
Source Code
REPORT demo_call_function.
CLASS demo DEFINITION.
PUBLIC SECTION.
CLASS-METHODS main.
ENDCLASS.
CLASS demo IMPLEMENTATION.
METHOD main.
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 ).
CALL FUNCTION 'READ_SPFLI_INTO_TABLE'
EXPORTING
id = carrier
IMPORTING
itab = itab
EXCEPTIONS
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 ).
LEAVE PROGRAM.
WHEN 2.
cl_demo_output=>display(
'Undefined error in function module' ).
LEAVE PROGRAM.
ENDCASE.
cl_demo_output=>display( itab ).
ENDMETHOD.
ENDCLASS.
START-OF-SELECTION.
demo=>main( ).
Description
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.