Tuesday, April 7, 2009

Combining three different aspects of PI in one shot

Combining three different aspects of PI in one shot

 

This web log describes how to combine three different aspects of PI (ASMA, AF Module and variable substitution) in one shot.

 

Requirement:

Set Receiver File Name as Payload Attribute Value:

Receiver file name should be “ORDERS.xml” where will be having the value of an attribute named “order_no” from Payload.

 

Brief Solution:

1. Using dynamic configuration, set the attribute value of payload dynamically to ASMA

2. Using AF module, write the value of ASMA in a variable

3. Using the variable substitution, set the receiver file name schema

 

Step 1: Dynamic Configuration

In message mapping, create a UDF that will store the value of the attribute “order_no” dynamically in the adapter specific message attributes named “FileName”

 

Java Code for UDF is below.

 

DynamicConfiguration conf = (DynamicConfiguration) container.getTransformationParameters().get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);

 

DynamicConfigurationKey FileName = DynamicConfigurationKey.create("http:/"+"/sap.com/xi/XI/System/File","FileName");

 

conf.put(FileName, a);

 

return "";

 

 


Step 2: AF Modules

Now as we have set the value of an attribute from payload in ASMA so we will write its value in a variable “message.interface”

In the receiver CC, under Modules tab, we will call an AF module “AF_Modules/DynamicConfigurationBean” before the “Call SAP Adapter”.

 

In the module configuration, we will set the following information.

key.0 = write http://sap.com/xi/XI/System/File FileName

value.0 = message.interface

 

Step 3: Variable Substitution

We have the value in “message.interface” so we will assign it to variable substitution.

 


The value of this variable substitution will be used in the receiver file name schema.

 


Receiver File Name Schema = + % + + %.xml

For example: ORDERS%order_no%.xml

 

Since we are not going to use ASMA in our receiver File name schema rather we are using the variable substitution so make sure that the ASMA is unchecked in your receiver CC.

 


 

Another Simple way

There is a simple way to achieve the above requirement “Set Receiver File Name as Payload Attribute Value” and the way is to write the UDF to store the value dynamically in ASMA.

 

UDF code will be as below.

 

String str = “ORDERS” + a +  “.xml”

 

DynamicConfiguration conf = (DynamicConfiguration) container.getTransformationParameters().get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);

 

DynamicConfigurationKey FileName = DynamicConfigurationKey.create("http:/"+"/sap.com/xi/XI/System/File","FileName");

 

conf.put(FileName, str);

 

return "";

  


But in this web log I have just described the possible ways to combine three different aspects of PI (ASMA, AF Module and Variable substitution) in one single shot.