Start of Content Area

Function documentation Function Modules  Locate the document in its SAP Library structure

Use

You can use the CALL FUNCTION statement to call function modules. To do so, enter the name of the function module in transaction SM30 in the table RSPLF_FDIR.

EXPORTING, IMPORTING, and CHANGING parameters can be transferred to the function modules. The parameters must be simple types (F, I, D, STRING, and characteristic and attribute types). Class references, structures, and table parameters are not permitted.

All compulsory IMPORTING parameters of a function module have to be supplied.

If the function module triggers an exception, you have to work with the MESSAGE ... RAISING construct. Class-based exceptions are also allowed. The notifications of the function module are copied to the log.

Example

The function module UPF_DISTR_RATE_GET is called in the following example.

DATA FISCPER TYPE 0FISCPER.

DATA FISCYEAR TYPE 0FISCYEAR.

DATA RATE TYPE F.

DATA KYF TYPE KEYFIGURE_NAME.

FOREACH FISCYEAR, KYF.

FISCPER = OBJV( ).

CALL FUNCTION UPF_DISTR_RATE_GET

EXPORTING

I_FISCPER = FISCPER

I_VERSION = 'OPTIMISTIC'

IMPORTING

E_RATE = RATE.

{KYF,FISCYEAR} = { KYF, FISCYEAR } * RATE.

ENDFOR.

The following example shows how the use of the MESSAGE … RAISING statement when an exception is triggered.

FUNCTION UPF_DISTR_RATE_GET.

*"--------------------------------------------------------------------

*"*"Local interface:

*" IMPORTING

*"     REFERENCE(I_FISCPER) TYPE  /BI0/OIFISCPER

*"     REFERENCE(I_VERSION) TYPE  STRING DEFAULT 'OPTIMISTIC'

*" EXPORTING

*"     REFERENCE(E_RATE) TYPE  F

*"     REFERENCE(E_FISCYEAR) TYPE  /BI0/OIFISCYEAR

*" EXCEPTIONS

*"     ERROR

*"--------------------------------------------------------------------

DATA: L_FISCPER_3 TYPE N LENGTH 3.

L_FISCPER_3 = I_FISCPER+4(3).

IF I_VERSION = 'OPTIMISTIC'.

E_RATE = l_FISCPER_3 / 5.

ELSE.

E_RATE = l_FISCPER_3 / 7.

ENDIF.

E_FISCYEAR = I_FISCPER(4).

IF L_FISCPER_3 IS INITIAL OR E_FISCYEAR IS INITIAL.

MESSAGE E001(UPF) WITH 'Initial Values'(TIV) RAISING ERROR.

ENDIF.

ENDFUNCTION.

 

End of Content Area