Function Module Important
Function Module Important
Function Module Important
manuals. Please contact [email protected] if you have any SAP training needs, or visit www.ERPtips.com for more information.
Written by Rehan Zaidi and John Verbestel Published by Klee Associates, Inc.
Copyright Klee Associates, Inc., 2008, 2009
Although created and referenced as the function group ZMAT, the underlying program is named SAPLZMAT. The SAPL prefix defines this program as a
ABAP Programming Language Rev. 09/10/2008 1
SAPtips Sample ABAP Programming Overview of Function Groups and Function Modules
function group, and is created automatically by the Function Builder, SAP Transaction SE37. The program is organized by a series of Include programs for handling global data, and each individual function module. Function Modules are created separately, and although unique to the SAP system, they must be assigned to a Function Group.
The following popup will request the details of the function group. Customer function groups should begin with a Z or a Y.
Rev. 09/10/2008
After saving, the function group will be requested to be assigned to a package, then a change request for transport and control requirements.
Rev. 09/10/2008
3. Define the interface to the function module. The Attributes of the function module should be reviewed first, as it controls the behavior of the overall function module.
The processing type controls the behavior of the function module. Normal Function Module Used for modularizing code and is not externally visible to other systems, but globally visible within the same SAP software system. Visible to external systems, and thus can be called via the RFC gateway. Denotes the use of the function module for Asynchronous update purposes. The three sub-selections pertain to the database logical unit of work and when the function module is executed in the context of the update task. More information can be found under Asynchronous Update Techniques.
Rev. 09/10/2008
The interface is based on the following: Inbound Data to be received from the calling program
Note the commonality with subroutines, where you can pass by reference (Default) or pass by value. Optional parameters can be assigned a default value, and do not need to be provided by the calling program. Outbound Data to be returned to the calling program
Changing Data to be received and returned using the same reference variable
Tables Obsolete interface for passing arrays of information. Use global table types going forward, in combination with the Changing interface. However, many delivered function modules still use the Tables interface.
Rev. 09/10/2008
Exceptions Exceptions, resulting in non-zero values of the system variable SYSUBRC. Exceptions are raised using the RAISING <exception> command in the source code of the function module.
In the figure above, the exception NOCUSTOMERFOUND is declared. Function Modules now have the added capability to use exception classes. This will be described in the Introduction to Object Oriented ABAP unit. 4. Enter the source code.
Rev. 09/10/2008
The source code will show the current interface as comment statements. Do not try to change the comment statements as it will make no difference to the interface. Note the use of the RAISE statement in the code above to trigger an exception. When the RAISE statement occurs, the program processing jumps to the ENDFUNCTION, and the control is passed back to the calling application.
The next screen will request the input parameters for the function module being tested.
Rev. 09/10/2008
Click Execute or Execute in Debugging once the input fields are entered. The results are shown in the next image.
The above was a successful test, and all the return parameters can be viewed directly. It can be seen that three records were returned in the T_Salesinfo table, and that the export structure E_Cust_Detail has information contained within. If the test failed, a result would appear as the next screen demonstrates. The exception is displayed as the main result, and all other export fields are empty.
Rev. 09/10/2008
Rev. 09/10/2008
By entering the name of the function module in the CALL FUNCTION field, and pressing Enter, the relevant function module call will be added directly in the program at the cursor.
10
Rev. 09/10/2008
The following can be noted, when using the Pattern button to insert the function module call: All interface parameters and exceptions are imported. Optional parameters, Importing parameters, and exceptions are automatically commented out. A basic if statement is added to handle any exceptions, and a commented out message statement.
You may then pass appropriate values to the function module to get the desired result. You must define suitable data objects that have types compatible to the parameters of the function module in question.
Rev. 09/10/2008
11
Legal Speak: Purchase of this book or acquisition at an ERPtips class, constitutes an implied agreement by the purchaser to a limited, license granted to the purchaser by Klee Associates, Inc., specifically for purposes limited to improving your personal knowledge of SAP software which does not in any way compete with Klee Associates. This manual is protected by copyright law, and is sold or is part of an ERPtips class with the following conditions: The manual will be used for your personal professional development. The manual will not be physically copied for distribution to other individuals or converted to an electronic copy for distribution to other individuals, unless copyright permissions for copying have been acquired from Klee Associates, Inc. The manual will not be used to conduct training classes by you or other individuals, without the written permission of Klee Associates, Inc. Inclusion of the concepts in this book in any internal client training material is allowed if the source of the concepts is acknowledged as follows: Copyright 2008, 2009 All rights reserved. Used with permission. Klee Associates, Inc. NO WARRANTY: This documentation is delivered as is, and Klee Associates makes no warranty as to its accuracy or use. Any use of this documentation is at the risk of the user. Although we make every good faith effort to ensure accuracy, this document may include technical or other inaccuracies or typographical errors. Klee Associates reserves the right to make changes without prior notice. ERPtips is a valued resource for thousands of clients and consultants worldwide. Visit our web site for more information about upcoming training, books, and newsletters. www.ERPtips.com ERPtips is a registered trademark of Klee Associates, Inc. No Affiliation: Klee Associates, Inc. and this publication are not affiliated with or endorsed by SAP AG. SAP AG software referred to on this site is furnished under license agreements between SAP AG and its customers and can be used only within the terms of such agreements. SAP AG is a registered trademark of SAP AG. All other product names used herein are trademarks or registered trademarks of their respective owners.
12
Rev. 09/10/2008