You are on page 1of 10

User Guide CUSTOMER

Document Version: 1.1 – 2019-07-24

Creating Your Own Function Modules


SAP S/4HANA Migration Object Modeler,
SAP S/4HANA 1610 FPS01 and higher
Typographic Conventions

Type Style Description

Example Words or characters quoted from the screen. These include field names, screen titles,
pushbuttons labels, menu names, menu paths, and menu options.
Textual cross-references to other documents.

Example Emphasized words or expressions.

EXAMPLE Technical names of system objects. These include report names, program names,
transaction codes, table names, and key concepts of a programming language when they
are surrounded by body text, for example, SELECT and INCLUDE.

Example Output on the screen. This includes file and directory names and their paths, messages,
names of variables and parameters, source text, and names of installation, upgrade and
database tools.

Example Exact user entry. These are words or characters that you enter in the system exactly as
they appear in the documentation.

<Example> Variable user entry. Angle brackets indicate that you replace these words and characters
with appropriate entries to make entries in the system.

EXAMPLE Keys on the keyboard, for example, F 2 or E N T E R .

CUSTOMER Creating Your Own Function Modules


2 © 2017 SAP. All rights reserved. Typographic Conventions
Document History

Version Date Change

1.0 2017-12-19 Initial Version

1.1 2019-07-24 Section error handling updated.

Creating Your Own Function Modules CUSTOMER


Document History © 2017 SAP. All rights reserved. 3
Table of Contents

1 Introduction ................................................................................................................................... 5
1.1 Overview .......................................................................................................................................... 5

2 Creating Your Own Function Modules ........................................................................................ 6


2.1 Overview .......................................................................................................................................... 6
2.2 COMMIT Control.............................................................................................................................. 6
2.3 Error Handling ................................................................................................................................. 6
2.4 Running the Function Module in Test Mode.................................................................................... 7
2.5 New Identifiers when Creating Data ................................................................................................ 7
2.6 Consistency Checks ........................................................................................................................ 7
2.7 Plausibility Checks........................................................................................................................... 8
2.8 Improving Performance .................................................................................................................. 8

CUSTOMER Creating Your Own Function Modules


4 © 2017 SAP. All rights reserved. Table of Contents
1 Introduction

1.1 Overview

The SAP S/4HANA migration cockpit uses function modules (internal SAP programs) that facilitate the transfer
of data to the SAP S/4HANA system. These function modules populate the SAP S/4HANA database with data.

In the SAP S/4HANA migration object modeler (transaction LTMOM), under Target Structures, you can view the
function modules that facilitate the transfer of data to the SAP S/4HANA system. Each function module transfers
data from a source structure by means of the relevant target structures to the SAP S/4HANA system database.

Note

A target structure does not always represent the SAP S/4HANA database structure. It rather represents
a specific business view of the database structure rather than the real database structure.

For migration objects delivered by SAP, SAP determines how the data in the source structure is accessed, and
how it is mapped to the relevant target structure by using predefined function modules. If required, you can create
your own function modules to facilitate the transfer of data to the SAP S/4HANA system. This guide outlines
important considerations for creating your own function modules.

Creating Your Own Function Modules CUSTOMER


Introduction © 2017 SAP. All rights reserved. 5
2 Creating Your Own Function Modules

2.1 Overview

Depending on your business requirement, you may want to create your own function modules to facilitate the
transfer of data to the SAP S/4HANA system.

The following sections outline important considerations for creating your own function modules.

2.2 COMMIT Control

The function module must not execute the COMMIT WORK command. The SAP S/4HANA migration cockpit
handles the COMMIT control.

2.3 Error Handling

The function module must use the ABAP Dictionary structure BAPIRET2 as a structure to return messages to the
SAP S/4HANA migration object modeler. In addition, note the following additional information regarding error
handling:

• SAP S/4HANA migration cockpit collects the error messages in its own application log by storing the
following information: message class, message number, and message variables. The message text is not
stored.
• No exceptions should be used. Instead all error, warning, and abort messages should be reported back to the
calling program in the standardized parameter Return.
• The function module must not cause the program to terminate. An abort message (message type A) should
be switched to an error message (message type E) to avoid that the program terminates.

Note that if the above points are not handled by the function module, you can create a wrapper to handle the error
messages. For example, the function module DMC_MIG_MAT_BOM acts as wrapper for function module
CSAP_MAT_BOM_MAINTAIN which handles the application log messages (starting at line 145).

CUSTOMER Creating Your Own Function Modules


6 © 2017 SAP. All rights reserved. Creating Your Own Function Modules
2.4 Running the Function Module in Test Mode

The function module should provide a test run flag so that it can be run in test mode to simulate the creation of
data in the target system. Alternatively, you can create a wrapper to provide a test run flag so that the program
can be run in test mode. For an example, see DMC_MIG_ACC_DOCUMENT_POST where different SAP function
modules (BAPI_ACC_DOCUMENT_CHECK, BAPI_ACC_DOCUMENT_POST) are called depending on whether the
function module runs in test mode or not.

Note that if the function module is called in test mode, ensure that the internal buffers are refreshed in order to
prevent buffer overflows and performance issues when calling the function module in a loop. You can also use a
wrapper to clear the buffers. For an example, see DMC_MIG_BANK.

2.5 Returning New Identifiers when Creating Data

We recommend that function modules return new IDs from data creation. This information is required by the SAP
S/4HANA migration cockpit in order to map the new internal key fields to the legacy key fields for dependent
objects. For example, if your function module will renumber internal material numbers, the newly created internal
number should be returned in the return message.

2.6 Consistency Checks

Regarding consistency checks, write-enabled methods must make all the necessary consistency checks to ensure
that the modified or newly created instance is consistent. For example, for all line items, the related header entry
must also be in the file.

Creating Your Own Function Modules CUSTOMER


Creating Your Own Function Modules © 2017 SAP. All rights reserved. 7
2.7 Plausibility Checks

All necessary plausibility checks (for example are all mandatory fields filled, do the values use the correct format,
and so on) must be done by the function module. Alternatively, you can create a wrapper to add plausibility
checks. For an example, see function module BAPI_ACC_DOCUMENT_CHECK for plausibility checks for an account
document.

2.8 Improving Performance

Regarding improving performance, note that the function module can process multiple instances at once (an
instance is a set of one or more records that have a defined relationship and that represent a business object type
such as Sales Order). This can be advantageous for objects that have a large amount of data.

CUSTOMER Creating Your Own Function Modules


8 © 2017 SAP. All rights reserved. Creating Your Own Function Modules
www.sap.com/contactsap

© 2017 SAP. All rights reserved.


No part of this publication may be reproduced or transmitted in any
form or for any purpose without the express permission of SAP AG.
The information contained herein may be changed without prior
notice.
Some software products marketed by SAP AG and its distributors
contain proprietary software components of other software
vendors.
National product specifications may vary.
These materials are provided by SAP AG and its affiliated
companies (“SAP Group”) for informational purposes only, without
representation or warranty of any kind, and SAP Group shall not be
liable for errors or omissions with respect to the materials. The only
warranties for SAP Group products and services are those that are
set forth in the express warranty statements accompanying such
products and services, if any. Nothing herein should be construed as
constituting an additional warranty.
SAP and other SAP products and services mentioned herein as well
as their respective logos are trademarks or registered trademarks of
SAP AG in Germany and other countries. Please see
www.sap.com/corporate-en/legal/copyright/index.epx#trademark
for additional trademark information and notices.

Material Number: NA

You might also like