- Function modules are special external subroutines stored in a central library.
- Can be created users own function modules.
- The main difference between a function module and a normal ABAP/4 subroutine is a clearly defined interface for passing data.
- The calling program and the called function module have separate work areas for ABAP/4 Dictionary tables.
- Several function modules can be combined to a function group in the program library with the attribute type F with definition of global data that can be accessed from all function modules of one function group.
Interfaces:
- Import parameter:
- Pass data from the calling program to the function module. Cannot be overwritten, even when passed by reference.
- Export parameters:
- Pass data from the function module back to the calling program. Always optional.
- CHANGING parameter:
- Passed by reference or by value and result.
- Act simultaneously as import and export parameters.
- They change the value passed to the function module and return it to the calling program.
- Table parameters:
- Internal tables.
- Treated like changing parameters and are always passed by reference.
- Exception:
- Used to handle error scenarios which can occur in function modules.
- Proposal - default value for optional parameters.
- Reference field|structure, Reference type - used for typing of formal parameters.
- Calling Function Modules:
[EXPORTING <f1> = <a1> ... <fn> = <an>]
[IMPORTING <f1> = <a1> ... <fn> = <an>]
[CHANGING <f1> = <a1> ... <fn> = <an>]
[TABLES <f1> = <a1> ... <fn> = <an>]
[EXCEPTIONS <e1> = <r1> ... <en> = <rn> [ERROR_MESSAGE = <rE>] [OTHER = <rO>]].
- EXPORTING - the formal parameters must be declared as import parameters in the function module.
- IMPORTING - the formal parameters must be declared as export parameters in the function module.
- EXCEPTIONS - <ri> is a numeric literal that is assigned to SY-SUBRC if the exception is raised. <rE> is used for additional exception ERROR_MESSAGE if a message of types A, E was issued in the function module without RAISING option.
- OTHERS - used to handle all exceptions that are not specified explicitly in the list. The same number <ri> can be used for several exceptions.
- Programming Function Modules:
....
RAISE <exception>.
....
MESSAGE ... RAISING <exception>.
....
ENDFUNCTION.
- If an internal subroutine is needed, the program code of internal subroutines can be placed directly behind the ENDFUNCTION statement of a module.
- This subroutines can be called from all modules of the function group, but for clarity, should be called only from the function module behind which it is written.
- To create internal subroutines that can be called from all modules of one function group <fgrp>, use special INCLUDE programs L<fgrp>F<xx>.
- We can open these INCLUDE programs easily by double clicking their names in the main program SAPL<fgrp> after selecting Main program on the Function Library->Maintain Function Modules screen.
No comments:
Post a Comment