Blog > SAP AIF – Using Init Function Before Mapping and Init Function Before Processing

SAP AIF – Using Init Function Before Mapping and Init Function Before Processing

Izabela Bogórska SAP Integration Consultant
icon__calendar 2021-02-04

In this article you will learn:

  • When you can use Init Function Before Mapping
  • When you can use Init Function Before Processing

Reading time: 8 minutes

Introduction

During implementation of an AIF Interface it can happen that some additional logic needs to be added before or after mapping is being done, but still before action processing. Then Init Function Before Mapping and  Init Function Before Processing comes to help us.

Init Function Before Mapping - Mapping - Init Function Before Processing - Action


To define any of those functions go to: /AIF/CUST and then: Interface Development->Define Interfaces

Define Interfeces in SAP AIF


After choosing the interface you can provide Init Function Before Mapping and / or Init Function Before Processing, depending on your needs.

Providing Init Function Before Mapping/Init Function Before Processing


Init Function Before Mapping

You can use this function module to modify or manipulate the data in the source and destination structures before the mapping defined in the AIF is executed.

The function module you use here must have the same signature as the template function module /AIF/FILE_TEMPL_INIT_MAPPING.

The best way to create a correct object is to copy provided template function module /AIF/FILE_TEMPL_INIT_MAPPING into the new one:

Copy Function Module


This way you assure that the function is having the correct signature.

By default your module will be created with a BREAK-POINT inside, which you can use for testing purposes and remove afterwards.

You can manipulate both – destination (“DATA”) and source (“RAW_STRUCT”) structures. Because the template provided by SAP is general-purpose and can be used with all interfaces, those parameters won’t have the predefined structure. Depending on what data you want to manipulate, it is required that you specify the correct data type of the source and destination structures in the newly created function module.

Function-Module-ZINITT_Mapping


After the logic is implemented and the new function module is active we need to add it to the Interface.

To configure this functionality go to:

/AIF/CUST and then: Interface Development->Define Interfaces , choose your interface and provide the name of your custom FM in the field below.

Define Interfaces Move Corresponding Structures Init Function Before Mapping


And that’s it. You have just configured Init Function Before Mapping.

Init Function Before Processing

You can use this function module to modify or manipulate the data in the destination structure after mapping defined in the AIF is executed, but before the processing of the actions starts in the SAP. The init function is processed at the beginning of an action call.

The function module you use here must have the same signature as the template function module /AIF/FILE_TEMPL_INIT_PROCESS.

To create a correct object copy provided template function module /AIF/FILE_TEMPL_INIT_PROCESS into your own one:

Copy Function Module ZINIT_PROCESSING


This way you assure that the function is having the correct signature.

The same, like for Init Function Before Mapping,  by default your module will be created with a BREAK-POINT inside, which you can use for testing purposes and remove afterwards.

For Init Function Before Processing you can only manipulate destination (“DATA”) structure. It will not have a predefined structure as well, so it is required that you specify the correct data type in the newly created function module.

Function module ZINIT_PROCESSING


After the logic is implemented and the new function module is active we need to add it to the Interface.

To configure this functionality go to:

/AIF/CUST and then: Interface Development->Define Interfaces, choose your interface and provide the name of your custom FM in the field below.

Define Interfaces Move Corresponding Structures Init Function Before Processing


And that’s it. You have just configured Init Function Before Processing.

Use cases and summary

Now, when you know how to configure this functionality,  you would probably like to know some examples of the use-cases for both types of functions.

Init Function Before Mapping can be used when:

  • We are processing an IDOC and we need to add additional segments and / or lines. For instance, you need to append an additional line with an information about a default business partner
  • We need to modify some information in the source structure  because this data is being used during mapping to select additional information. For instance, you need to modify business partner ID, because then this value is used in mapping for gathering information about the address
  • You need to validate if the message doesn’t contain duplicates

Init Function Before Processing can be used when:

  • You need to validate if the destination structure contains master data which is already present in the system
  • You need to perform calculations based on the values in the destination structures like for instance total weight of the materials
  • You need to add the discount code based on the total purchase of the customer in the current year

The use-cases I gave are just an example and they will vary depending on the project and requirements. But they can be a good point in better understanding of the capabilities of those functionalities.

Summary

Now, you are ready to use the  Init Function Before Mapping and  Init Function Before Processing in your AIF projects.

Want to learn more about SAP AIF? Check other articles about SAP AIF on Int4 blog.

Read also:

1. SAP AIF – How to create Interface Variants

2. Set up interface in SAP AIF Interface Monitor (/aif/ifmon)

 

 

Izabela Bogórska SAP Integration Consultant
Working with SAP technologies since 2007, including more than 10 years of SAP Development. Involved in several international projects as an ABAP developer or Team Lead. Iza is certified in ABAP development. and always eager to learn about new SAP technologies. In her job she combines both technical and interpersonal skills.

Contact us

If for any reason, the thought of reaching out to us has crossed your mind, then by all means do not hesitate to get in touch with us, as we are more than happy to put to rest all of your concerns.