Introduction

We have so far looked at handling TPM On Integration Suite and seen how you can build dynamic Trading Partner Configuration on TPM without changing anything on your IFlows. In other words, other than building EDI Mappings, you do not do anything on your Integration Flows and everything is handled through TPM Configuration. TPM also provides additional customizations at a Trading Partner Level called “Parameters“. You can define Parameters at various levels of TPM and then use them within your Message Mapping and / or MAGs. Before looking at how how to use Parameters in your Message Mapping ( and / or MAGs), lets take a step back and understand why we need TPM Parameters.

Our Requirements

Lets look at our scenario from Part 1, we have trigged a Delivery from ERP using a DESADV.DELVRY03 IDoc, and then transformed this to a EDIFACT DESADV D96A. What if within your EDI transformation you had to assign additional dynamic parameters that are not a part of your IDoc? For example, you want to assign the below Contact Information in your DESADV D96A Message and what if they are not a part of your ERP Configuration and the data is not present in your IDoc.

  • Consignor ID : NAD+CZ
  • Seller ID: NAD+SE
  • Carrier ID: NAD+CA
  • Consignee ID: NAD+CN

These segments are documented here and what if all of these values need to be set in your mapping but they are not coming in from the Source. Lets say below are the values that need to be defined when we send our EDI Message

QualifierValue
ConsignorIDCUST1_CONSIGNOR1
SellerIDSELF_SELLER
CarrierIDCUST1_CARRIER1
ConsigneeIDCUST1_CONSIGNEE1
TPM Parameters Requirements

Snippet of how our EDI Message should look like

NAD+CZ+CUST1_CONSIGNOR1::92'
NAD+SE+SELF_SELLER::92'
NAD+CA+CUST1_CARRIER1::92'
NAD+CN+CUST1_CONSIGNEE1::92'

The Solution

As you would have imagined, this is where Parameters in TPM come into picture where you can define custom parameters that you can then use in your Mappings. There are different levels at which you can define Parameters in TPM. Lets look at those first.

Within Integration Suite TPM you can define Parameters are 4 different levels.

  • Company Profile : Parameters assigned to the Company and available across all TPM Agreements ( Global Scope )
  • Trading Partner: Parameters assigned to a specific Trading Partner and available only to the Agreement of that Trading Partner
  • Agreement – Transaction : Parameters assigned to a specific Agreement and its Transaction and available only to that Agreement Transaction. These are called “Activity Parameters
  • Global MAG Parameters: Parameters assigned to a MAGs. These are parameters that can be be defined within a MAGs. Equivalent to this on your Message Mapping is Externalized Properties that are defined in your Integration Flow that you can then access within your Message Mapping.

The Parameters that we have defined in our initial requirements will hence be defined at the below levels.

Parameter KeyValueLevel
ConsignorIDCUST1_CONSIGNOR1Trading Partner
SellerIDSELF_SELLERCompany Profile
CarrierIDCUST1_CARRIER1Agreement : Transaction ( Activity Parameter)
ConsigneeIDCUST1_CONSIGNEE1Agreement : Transaction ( Activity Parameter)
TPM Parameters and Levels

We will define these Parameters in TPM and then use them in our Message Mapping.

Define Parameters

We will extend our scenario from Part 1, to use these Parameters. Lets gets started.

Define a Company Profile Parameter

Company Profile Parameters are parameters defined at a Company Profile Level and hence are accessible across all Trading Partners and Agreements. They have a Global Scope so as to speak.

We will now create a Parameter called SellerID in our Company Profile. Go to Design -> B2B Scenarios -> Company Profile -> Parameters -> Create. Provide the Parameter Key and Value for your Company Profile Parameter. SellerID and SELF_SELLER in our case

Create a Company Profile Parameter in TPM
Provide the Parameter Key and Value for your Company Profile Parameter

Define a Trading Partner Parameter

Trading Partner Parameters are specific to a Trading Partner and are accessible across all Agreement where this Trading Partner is involved. We will now create a Parameter called : ConsignorID for our Trading Partner – CUSTOMER1 in this case. Go to Design -> B2B Scenarios -> Trading Partners -> CUSTOMER1 ( or your Trading Partner) ->Parameters -> Create.

Provide the Parameter Key and Value for your Trading Parameter. ConsignorID and CUST1_CONSIGNOR1 in our case

Create a Trading Partner Parameter in TPM
Provide the Parameter Key and Value for your Trading Partner Parameter

Define a Agreement Parameter – Activity Parameter

Activity Parameters are defined at a Trading Partner Agreement Transaction and they are accessible only within those Transactions of the Agreement. We will now create 2 Parameters on the Agreement Transaction we have defined in Part 1. Go to, Design -> B2B Scenarios -> Agreements ->Go to Agreement from Part 1 or your specific Agreement -> B2B Scenarios ->Transactions -> Edit

Create a Activity Parameter at a Trading Partner Level.

When you are in Edit mode, of your Agreement(Transaction), you will see the Activity Parameters at the bottom. Click on Add Parameters. You will see options

  • Extend from Company : To Assign Company Profile Parameters
  • Extend from TP: To Assign Trading Partner Parameters
  • Create Activity Parameters: To Create Activity Parameters

For this section we will focus on Create Activity Parameters and create 2 Parameters as per our requirements. Select option : Create Activity Parameters and create the below Parameters and Values.

  • CarrierID – CUST1_CARRIER1
  • ConsigneeID – CUST1_CONSIGNEE1
Create a Activity Parameter in TPM Agreement Transaction
Create a Activity Parameter for CarrierID
Create a Activity Parameter for ConsigneeID

Ensure you save your Agreement after you have created the below Activity Parameters.

Activity Parameters are created in your TPM.

Extend ( or Assign) Company and Trading Partner TP Parameters to your Agreement

The 2 parameters we created in previous section will now be assigned ( or Extend ) to our Agreement Transaction. Go to, Design -> B2B Scenarios -> Agreements ->Go to Agreement from Part 1 or your specific Agreement -> B2B Scenarios ->Transactions -> Edit.

Extend ( or Assign) Company and Trading Partner TP Parameters to your Agreement

Click on Add Parameters and select Option Extend from Company. Select the Company Profile Parameter we created in the previous section ( SellerID )

Extend From Company for Parameter's in TPM
Select the Company Profile Parameter

Similarly Click on Add Parameters and select Option Extend from TP. Select the Trading Partner Parameter we created in the previous section ( ConsignorID)

Extend From TP for Parameter's in TPM
Select the Trading Partner TP Parameter

Save your TPM Agreement, and Activate ( Update) the Agreement Changes

Save your TPM Agreement, and Activate ( Update) the Agreement Changes

Access TPM Parameters in your Message Mapping

So far so good, we have extended our Company Profile, Trading Partner and Agreement to use Parameters. The next step is to access and leverage these Parameters in the runtime in your Message Mapping. Every time you Activate or Update your TPM Agreement, data from your TPM is deployed to the Partner Directory within Integration Suite.

To be able to read the TPM Parameters in your Message Mapping you will need to use a Groovy Script that will read the TPM Profile, access the Partner Directory content and then save these TPM Custom Activity Parameters as Properties in your Integration Flow.

Ensure Allowed Headers in your Custom Mapping Flow

Ensure you have a * in your Allowed Headers in your Custom Mapping Iflow that is invoked from TPM or at the minimum you allow the header SAP_TPM_ACTIVITYPARTNER_ID. In my case I am allowing only the header SAP_TPM_ACTIVITYPARTNER_ID but you can also allow a * or a SAP*

Allowed Headers to allow SAP_TPM_ACTIVITYPARTNER_ID or 
* or SAP* to access TPM Activity Parameters.

Use Groovy to Access Custom Activity Parameters of your TPM

Use the below Groovy Script in your Custom IFlows where you have your Custom Message Mappings. This groovy script accesses the Standard TPM header SAP_TPM_ACTIVITYPARTNER_ID ( more on this in another post) and then accesses all the Custom Activity Parameters and sets them as Message Properties. Of course you should use this as a Reusable Groovy Script. This is the same approach that is used in the standard IFlow of SAP in the Groovy Script : Reusable Groovy Scripts V2 ( callPDwithHeaderParameters.groovy)

Once you have used this Groovy, you can then access these Custom Activity Parameters as Properties in your message mapping. This is a very standard CPI Approach that is documented here on SAP Help : Access Header and Properties in Message Mapping

import com.sap.gateway.ip.core.customdev.util.Message;
import com.sap.it.api.pd.PartnerDirectoryService;
import com.sap.it.api.ITApiFactory;
import groovy.json.JsonSlurper;
import com.sap.it.api.pd.BinaryData;

def Message processData(Message message) {
	def service = ITApiFactory.getApi(PartnerDirectoryService.class, null);
	def partnerID = message.getHeaders().get("SAP_TPM_ACTIVITYPARTNER_ID");
	def customActivityParams = service.getParameter("SAP_TPM_CustomActivityParams", partnerID, BinaryData.class);
    if (customActivityParams != null){
        def customActivityParamsStr = new String(customActivityParams.getData());
        def customActivityParamsJson = new JsonSlurper().parseText(customActivityParamsStr);
        customActivityParamsJson.each{
            paramKey, paramValue -> message.setProperty(paramKey, paramValue);
        }
    }
  return message;
}

Update your Mapping to for the below Fields

As per our initial requirement we wanted to map the NAD Segments of our EDI Message with these Custom Parameters. We will now update our Graphical Message Mapping to use these Parameters. See snippet below for the XML

<G_SG2>
	<S_NAD>
		<D_3035>CZ</D_3035>
		<C_C082>
			<D_3039>${property.ConsignorID}</D_3039>
			<D_3055>92</D_3055>
		</C_C082>
	</S_NAD>
</G_SG2>
<G_SG2>
	<S_NAD>
		<D_3035>SE</D_3035>
		<C_C082>
			<D_3039>${property.SellerID}</D_3039>
			<D_3055>92</D_3055>
		</C_C082>
	</S_NAD>
</G_SG2>
<G_SG2>
	<S_NAD>
		<D_3035>CA</D_3035>
		<C_C082>
			<D_3039>${property.CarrierID}</D_3039>
			<D_3055>92</D_3055>
		</C_C082>
	</S_NAD>
</G_SG2>
<G_SG2>
	<S_NAD>
		<D_3035>CN</D_3035>
		<C_C082>
			<D_3039>${property.ConsigneeID}</D_3039>
			<D_3055>92</D_3055>
		</C_C082>
	</S_NAD>
</G_SG2>

Test Your Flow

Thats it, you can now test your flow. Ensure you have Trace on to see what’s happening under the hood. Trigger your IDoc from ERP and you will notice now that our Groovy Script in the Custom Mapping Flow will use the Header : SAP_TPM_ACTIVITYPARTNER_ID and then access all our Parameters and set them as Message Properties.

SAP_TPM_ACTIVITYPARTNER_ID
Custom Activity Parameters are set a Message Properties in your MPL
EDI File DESADV now has the Parameters from TPM

What about Global Parameters of MAGs

As discussed in this SAP Community thread : SAP Integration Suite Trading Partner Management: How to use parameters?, you can within MAGs defined Global Parameters and then use them in your MAGs. The equivalent to these is defining Externalized Properties in your Integration Flow and using them in your Message Mapping. So, if you use MAGs, you can use Global Parameters of MAG and if you use Message Mapping you can use Externalized Properties.

If you want to access Company Profile, Activity Parameters and Trading Partner Parameters, in your MAG, the solution is defined in this Community Thread : SAP Integration Suite Trading Partner Management: How to use parameters?

Final Thoughts

TPM Parameters provide additional layer of configuration and externalization to your Trading Partner Mapping. You have options to access TPM Parameters either using MAGs or Message Mapping. Within MAGs you use the functions and within Message Mappings you use a Groovy Script to access the TPM Profile and the parameters as Properties.

In real EDI projects, the need for such Parameters is very very real, as you want to add Dynamic content to the mapping that are not standard EDI headers. When you build common mappings for Trading Partner Management and want to handle dynamic values in the runtime, TPM Parameters will be the key!

References

Additional Blogs from this Series