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

In this article you will learn:
- When you can use Init Function Before Mapping
- When you can use Init Function Before Processing[/list]
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.
To define any of those functions go to: /AIF/CUST and then: Interface Development->Define Interfaces
After choosing the interface you can provide Init Function Before Mapping and / or Init Function Before Processing, depending on your needs.
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:
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.
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.
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:
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.
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.
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[/list]
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[/list]
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)
And if you want to learn more about this missing link of your SAP S/4HANA testing strategy, make sure to visit the Int4’s course called “Avoid SAP S/4HANA Project Delays with Third-Party System Service Virtualization” available here:
Popular tags
ABAP int4 INT4 IFTT Int4Interview S/4HANA SAP AIF SAP CPI sap integration