Skip to Content
Author's profile photo Britta Mangei

How to Determine a Single Key Field in a Table Using a Key Field Rule Function Module

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:

  1. Create a single index table and add the required key fields
  2. Define the key fields as single key field in the interface specific features of the AIF interface
  3. Mark the key field rule check box and add a key field rule function module for the key field
  4. Implement the function module to determine the correct value for the key field and insert it into the single index table entry
Example

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.

/wp-content/uploads/2016/09/scn_idoc1_1037008.png

1. Create Single Index Table

Create a single index table and add field ship_to. Use PARTNER_VB as data element.

/wp-content/uploads/2016/09/scn_idoc2_1037027.png

2. Define Key Fields

In AIF Customizing, add the single index table to the interface under Define Namespace Specific Features.

/wp-content/uploads/2016/09/scn_idoc3_1037028.png

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.

/wp-content/uploads/2016/09/scn_idoc4_1037029.png

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.

/wp-content/uploads/2016/09/scn_idoc5_1037039.png

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?

  1. Loop over the IDOC_DATA where SEGNAM equals the name of the segment containing your key field.
  2. Convert the SDATA part of the current segment to the corresponding structure.
  3. Check if the current segment contains the identifier of your key field.
  4. The identifier has been found. Change the single index table entry and write the value of the segment field into the index table field.

/wp-content/uploads/2016/09/scn_idoc6_1037069.png

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

/wp-content/uploads/2016/09/scn_idoc7_1043282.png

Single index table

/wp-content/uploads/2016/09/scn_idoc8_1037071.png

This is one possibility to determine the value of a single key field which is contained inside a table in the message.

Assigned Tags

      1 Comment
      You must be Logged on to comment or reply to a post.
      Author's profile photo Lei Su
      Lei Su

      nice work