You have identified a field which you would like to use as a key field. The field is located in a table, which means it can occur multiple times with different values. However, for your scenario only a certain entry of the table is relevant. All other table entries can be ignored. Therefore, a single key field is enough. But how to determine the correct table entry to store the correct value in the single index table? The solution is to use a key field rule with a function module.
How does it work?
You need to perform the following steps to be able to store the key fields correctly:
- Create a single index table and add the required key fields
- Define the key fields as single key field in the interface specific features of the AIF interface
- Mark the key field rule check box and add a key field rule function module for the key field
- Implement the function module to determine the correct value for the key field and insert it into the single index table entry
In order to show how this works we will have a look at an IDoc of type DESADV. DESADV is the IDoc type for deliveries. The partner information is contained in segment E1EDKA2. The segment can occur multiple times containing different partners. In this example we are only interested in the ship-to party. The partner type is identified by the qualifier in field PARVW. For the ship-to party the qualifier is ‘WE’. The partner number itself is contained in field PARTN and should be stored as key field in the single index table.
1. Create Single Index Table
Create a single index table and add field ship_to. Use PARTNER_VB as data element.
2. Define Key Fields
In AIF Customizing, add the single index table to the interface under Define Namespace Specific Features.
In the next step, define the key fields under Interface Specific Features. Enter the key field specific data and select field PARTN of the E1EDKA2 segment as the field name.
3. Define Key Field Rule
In the definition of your key field mark the key field rule check box. Press enter. The rule details are now displayed. Create a new function module to determine the correct value for the single index field. Enter the name of the function module and create the function module using forward navigation.
4. Implement Function Module
Open the function module. The next step is to determine the correct segment containing the the required partner information.
In this example the IDoc enabler is used only input parameter IS_RAW_STRUCTURE is filled. In addition, if the scenario is an IDoc enabler scenario the data is not mapped to the AIF structure. Therefore the data type of the RAW structure is always /AIF/IDOC_CONTROL_DATA_REC. If you have an interface that is not using the IDoc enabler the data type of the RAW structure is the data type of the RAW structure of your interface.
/AIF/IDOC_CONTROL_DATA_REC contains the control record of the IDoc with type EDIDC and the data records of the IDoc. The data records are stored in a table with line type EDIDD.
What to do to get the right segment?
- Loop over the IDOC_DATA where SEGNAM equals the name of the segment containing your key field.
- Convert the SDATA part of the current segment to the corresponding structure.
- Check if the current segment contains the identifier of your key field.
- The identifier has been found. Change the single index table entry and write the value of the segment field into the index table field.
Check the result: Send a new IDoc and verify the displayed key field in Monitoring and Error Handling or directly in the single index table.
Monitoring and Error Handling
Single index table
This is one possibility to determine the value of a single key field which is contained inside a table in the message.