Function module exits allow you to implement your own functions and processing logic in standard SAP programs. To take advantage of a function module exit, you first need to create a project as described in the section
Creating an Add-on Project. Then, you must include the SAP enhancement that contains the function module exit you want to use in your project. From the main screen of the Project management transaction, proceed as follows:The system lists all the customer exits contained within the enhancements included in your project.
The system displays the exit’s corresponding function module, which has been prepared by an SAP application developer. You can fill this module with functions you want by calling the include program (called ZXnnnU01) contained within the module and inserting your own source code into it. Both the function module and the include program lie within the namespace reserved for customers.
The system asks you if you want to create the include program.
Using Predefined Interface Parameters
When you use a function module exit, you need to be aware of how your function module fits into the program logic of the standard R/3 program that calls it. When defining function module calls in its standard program, SAP specifies exactly what data can be transferred to and from the standard program. If the customer function call includes import and export parameters, the customer function module will itself have the same predefined interface.
You can not make changes to the general framework or to the interface of a function module exit’s function module. You are only allowed to use the special include program it contains to add your own programming logic. When you create the source code for your include program, be aware of the restrictions set by the function module exit’s interface. You can only transfer values to and from your include program if these values are included in the function module’s predefined interface.
Using Sample Code Provided by SAP
SAP sometimes supplies sample coding for the function module exits it provides. You can copy this sample code into your include program. To use sample code, proceed as follows:
If sample code exits, the system copies this code to your include program. If you have already written your own code in the include program, the system appends the sample to your code. You are free to alter the sample code as needed.
Declaring Global Data
SAP often supplies function module exits with predefined global data. Global data is required if, for example, SAP provides subroutines with a function module exit. All global data defined by SAP is stored in an include called LXnnnTOP, where nnn stands for the other characters in the function group. You can define your own global data in any function module exit.
Take advantage of the ABAP Workbench’s navigational features when creating global data definitions:
The system asks you if you want to define the object, since no data definition exists for it yet.
The system automatically creates a new include called ZXnnnTOP. Use this include to store all of the data definitions for your function module exit(s).
Creating Subroutines
SAP may include pre-programmed subroutines in certain function module exits. These predefined subroutines are stored in an include called LXnnnF00, where nnn stands for the other characters in the function group. You may call these routines from within your customer include program.
You can also create your own subroutines. To create new subroutines, use forward navigation in the ABAP Workbench and proceed as follows: Proceed as follows to create new subroutines:
Since the routine does not yet exist, the system asks if you wish to create it.
The system automatically creates an include called ZXnnnZZZ, where nnn stands for the other characters in the function group. This include should contain all subroutines used in your customer function modules.
The central include program (called ZXnnnU01) contains the commands FUNCTION and ENDFUNCTION. Therefore, you should not use the keywords FORM and ENDFORM in this include.
Calling Your Own Screens
You can call your own screens from within a customer function module. For example, you might want to call a screen that lets users carry out certain processes not available in a standard R/3 transaction. Use forward navigation in the ABAP Workbench to create your own screens and their flow logic. Proceed as follows:
The system asks if you want to create the screen and then branches to the Screen Painter.
To create PBO and PAI modules, proceed as follows:
The system creates the modules. At the same time, the system creates include programs that adhere to SAP’s naming standards.
Use Workbench navigation to create any other program objects (like events) that you want to include in your function module.