Function groups in ABAP

Share Embed Donate


Short Description

Function groups in ABAP...

Description

This segment from our 415 page ABAP Programming manual is being made available as a sample of our training 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

Unit 3 – Function Groups and Function Modules Overview of Function Groups and Function Modules The following figure describes the basic construct of a Function Group, which is a specialized program.

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

SAPtips Sample ABAP Programming Overview of Function Groups and Function Modules

1

Unit 3 – Function Groups and Function Modules

Klee Associates, Inc.

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.

Creating a Function Group Function groups are created using transaction SE37 (function builder). A Function Group is realized in the SAP Software system as a program, containing a logically related set of function modules. When creating function groups, realize that when a program (client) calls a function module, the function group and all its global data are instantiated and consume runtime memory until the end of the calling program (client lifetime). Do not overload your function group as it may result in effecting the performance of the calling program. Create the function group by selecting the menu path Goto  Function Groups  Create Group.

The following popup will request the details of the function group. Customer function groups should begin with a Z or a Y.

2

Rev. 09/10/2008

ABAP Programming Language

Unit 3 – Function Groups and Function Modules

Klee Associates, Inc.

After saving, the function group will be requested to be assigned to a package, then a change request for transport and control requirements.

Creating a Function Module Function modules are created using transaction SE37 (function builder). The standard SAP system has a number of predefined function modules. Function modules are best used for carrying out database updates and communicating with different SAP systems. In contrast to subroutines, function modules do not need to be defined in the source of your ABAP program. Function modules may have both input and output parameters. The input parameters can be mandatory or optional. You can also assign default values to parameters. Function modules also provide the option of exception handling, which catches errors when the function module executes. You may also test function modules from transaction SE37 before including them in your programs. Function Modules must begin with a Z_ or a Y_, and can be created as follows: 1. Enter the new function module name and click the Create button.

2. Assign the function group.

ABAP Programming Language

Rev. 09/10/2008

3

Unit 3 – Function Groups and Function Modules

Klee Associates, Inc.

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 



Remote Function Module 



4

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.

Update Function Module 

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

ABAP Programming Language

Unit 3 – Function Groups and Function Modules

Klee Associates, Inc.

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 

ABAP Programming Language

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

5

Unit 3 – Function Groups and Function Modules



Klee Associates, Inc.

Exceptions 

Exceptions, resulting in non-zero values of the system variable SYSUBRC.



Exceptions are raised using the RAISING 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.

6

Rev. 09/10/2008

ABAP Programming Language

Unit 3 – Function Groups and Function Modules

Klee Associates, Inc.

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.

Testing the Function Module The Function Builder has its own test workbench, and can be accessed using the TEST icon, the same one used in the ABAP Editor. On the main screen, select the test icon as demonstrated below.

The next screen will request the input parameters for the function module being tested.

ABAP Programming Language

Rev. 09/10/2008

7

Unit 3 – Function Groups and Function Modules

Klee Associates, Inc.

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.

8

Rev. 09/10/2008

ABAP Programming Language

Unit 3 – Function Groups and Function Modules

Klee Associates, Inc.

Working with Function Groups in the Object Navigator Use the package or the function group view in the object navigator (SAP Transaction SE80 to show the function group and it's modules so that they can be edited directly from the Workbench. An example is presented below:

ABAP Programming Language

Rev. 09/10/2008

9

Unit 3 – Function Groups and Function Modules

Klee Associates, Inc.

Using Function Modules in ABAP Programs For including function modules that already exist in the system, simply click on the icon from the ABAP Editor while in the Change mode. The dialog box (shown in the next figure) appears:

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

ABAP Programming Language

Unit 3 – Function Groups and Function Modules

Klee Associates, Inc.

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.

ABAP Programming Language

Rev. 09/10/2008

11

Unit 3 – Function Groups and Function Modules

Klee Associates, Inc.

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

ABAP Programming Language

View more...

Comments

Copyright ©2017 KUPDF Inc.
SUPPORT KUPDF