Skip to Content
Author's profile photo Stefan Grube

Copy value from Request message to Response message using DynamicConfigurationBean and dynamic header fields

Recently I worked on a scenario with two Idocs that are used as asynchronous request and response messages for ERP and a synchronous webservice.

For this scenario, I used SOAP adapter with async-sync brigde with help of RequestResponseBean and ResponseOnewayBean.

I wanted to populate fields in the response Idoc from the request Idoc. Here I had the challenge that the required values were only available in the Idocs, but not part of the request and response message of the web service, so I could not use the option with GetPayloadValueBean and PutPayloadValueBean, as it is described in this blog of Beena Thekdi:

Insert value from Request message to Response message using GetPayloadValueBean and PutPayloadValueBean

I wanted to use the dynamical header fields of the PI message to store the vales. Unfortunately, the SOAP adapter removes dynamic header field from request message, so the response message would not be able to access them. So I needed to find a way to keep the values.

I found the solution with the DynamicConfigurationBean that allows copying values form dynamical header fields to the module context and back. All adapter modules within the same module chain of the communication channel can access the parameter values in the module context.

I have already described this feature in this blog:

Unknown use case of DynamicConfigurationBean: Store file name to JMS header without mapping

Now the module chain of my SOAP adapter receiver channel looks like this:

Module Type Module Key
AF_Modules/DynamicConfigurationBean Local Enterprise Bean DC1
AF_Modules/RequestResponseBean Local Enterprise Bean RRB
sap.com/com.sap.aii.af.soapadapter/XISOAPAdapterBean Local Enterprise Bean SOAP
AF_Modules/DynamicConfigurationBean Local Enterprise Bean DC2
AF_Modules/ResponseOnewayBean Local Enterprise Bean ROB

I will not go into the configuration for RequestResponseBean and ResponseOnewayBean, as this is described in other blogs.

The module parameters for the DynamicConfigurationBean are following. In my scenario, I used the dynamic value “Value” with namespace “strDocNum”.

Those values might not be the best choices, however it works anyway.

Module Key Parameter Name Parameter Value
DC1 key.1 write strDocNum Value
DC1 value.1 module.strDocNum
DC2 key.1 read strDocNum Value
DC2 value.1 module.strDocNum

For the graphical mapping tool, it is necessary to create user-defined functions to store the values in the dynamical header fields and read them from there. Here are the functions that are used in my scenario:

PutDocNum is used in the request mapping

PutDocNum

public String PutDocNum(String docnum, String username, Container container) throws StreamTransformationException{

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

DynamicConfigurationKey keySource1 = DynamicConfigurationKey.create(“strDocNum“,”Value“);

if (conf != null) {

  conf.put(keySource1, docnum);

}

return username;

GetDocNum is used in the response mapping

Note: as the value DocNum was not part of the target message, the UDF was tied to another target field called username.

GetDocNum

public String GetDocNum(Container container) throws StreamTransformationException{

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

if (conf != null) {

    DynamicConfigurationKey keySource1 = DynamicConfigurationKey.create(“strDocNum“,”Value“);

    return conf.get(keySource1);

} else

    return “”;

Here is the link to the online help, the parameter value module.nn is still not mentioned:

Adding DynamicConfigurationBean in the Module Processor

Assigned Tags

      30 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Ricardo Viana
      Ricardo Viana

      Hey Stefan,

      Nice blog thanks for contribution !

      See ya

      Author's profile photo Former Member
      Former Member

      Hello Stefan,

      Thanks for sharing the details.

      I had created a document on a similar subject few days back - Dynamic Configuration Usages in SAP PI. You may find it interesting.

      Regards.

      Author's profile photo Former Member
      Former Member

      Hello Stefan,

      Thanks for sharing!

      Is your example config coincidental of an E-Invoice Mexico Project? 🙂

      Dynamic Configuration values names are same...

      Best regards,

      Fabian Engel

      Author's profile photo Stefan Grube
      Stefan Grube
      Blog Post Author

      Hi Fabian, You are right, I took this example while I did an implementation for E-Invoicing Mexico. The original solution comes with a ccBPM. I could not use it as my customer has PI 7.31 Java only. After my experience I recommend not use ccBPM for this scenario at all, as the async-sync bridge with adapter module is the superior solution. Regards Stefan

      Author's profile photo Former Member
      Former Member

      Thank you Stefan !! It works in PO 7.5 as well.

      Author's profile photo Former Member
      Former Member

      Hi Stefan,

      Thanks for the blog, I am able to use this feature in my requirement but I need to save multiple values. when I am executing the interface only last value saved is coming in all the fields. please take a look at the sequence and parameters:

      Capture11.PNG

      Capture122.PNG

      could you please help me to correct this?

      Thanks

      Navneet

      Author's profile photo Stefan Grube
      Stefan Grube
      Blog Post Author

      You only need the DynamicConfigurationBean twice. By the way: I think you do not need those beans for the RFC adapter, because the RFC adapter does not delete the dynamic header fields. Could you check this and confirm?

      Author's profile photo Former Member
      Former Member

      Thank you so much Stefan, I removed all beans from RFC and it worked perfectly.. 🙂

      Thanks

      Navneet.

      Author's profile photo Adam Sosnowski
      Adam Sosnowski

      Just for information:
      This trick does not work with all Adapter types. At least it does not work with HTTP_AAE (as of PO 7.50 SP03). The reason is, that the Supplemental Data (module context) gets deleted by Adapter Module sap.com/com.sap.aii.adapter.http/HttpAdapterBean.


      Since this is the place where the DynamicConfigurationBean stores the data with its "write" action, all data stored by the bean vanishes.

      Regards,
      Adam

      Author's profile photo Stefan Grube
      Stefan Grube
      Blog Post Author

      Hi Adam, good to know. I tested this with PI 7.11 and PI 7.31 SOAP adapter only. So I cannot assure if that works for any other adapter or for any other PI release. Do you know, if it works with the SOAP adapter in PO 7.5? Regards Stefan

      Author's profile photo Adam Sosnowski
      Adam Sosnowski

      Hi Stefan,

      yes, I had to switch from HTTP_AAE to SOAP receiver channel to make it work.

      Regards,

      Adam

      PS: There may be a way of preserving the context data of the request message for the response message without using DynamicConfigurationBean and it should work for any standard adapter module. It involves writing a tiny wrapper adapter module following the the approach presented here: Adapter Module: ExceptionCatcherBean
      I didn't try it, since it was only my fallback solution, but it should work.

      Author's profile photo Manoj Venkata Aditya Vempati
      Manoj Venkata Aditya Vempati

      Hi Stefan,

      Many thanks for this blog.

      Could you please let me know if these UDFs are used in request or response mappings?

      And to just let you know - in my scenario, I have to send the request IDoc number in the response IDoc. I can get either success or fault response from target system. I have three mappings in total - Request IDoc to SOAP mapping, SOAP response to response IDoc mapping and SOAP fault to response IDoc mapping.

      Regards,

      Aditya

      Author's profile photo Manoj Venkata Aditya Vempati
      Manoj Venkata Aditya Vempati

      I got this. Thank you once again.

      Regards,

      Aditya

      Author's profile photo Manoj Venkata Aditya Vempati
      Manoj Venkata Aditya Vempati

      Hi Stefan,

      I have a similar scenario and facing issue while creating response IDoc. Could you please check IDoc AAE receiver channel in ResponseOnewayBean

      Regards,

      Aditya

      Author's profile photo Andrey Petin
      Andrey Petin

      Hello Stefan.

      I am facing the problem being described.

      It would be good to use your approach but I have to save random number of values. I mean, there is 1..unbounded node in source message, and I have to save values of "ID" element from each node.

      OK, it is possible to write them into DC with UDF: keys will be Id1, Id2, .. IdN, namespace will be unique for these keys.

      But is it possible to configure DynamicConfigurationBean so that all keys from certain namespace would be saved in module data and be available in response message?

      Author's profile photo SAPenthusiast SAPenthusiast
      SAPenthusiast SAPenthusiast

      Thanks for this Stefan! I'll try this out as suggested by Praveen 🙂

      Author's profile photo Former Member
      Former Member

      Excellent blog, Stefan.

      Author's profile photo Former Member
      Former Member

      Thanks for such informative blog Stefan!

      I tried implementing this in REST adapter, the value is getting stored but is not getting fetched. Is it because of the REST adapter?

      Thanks,

      Pankaj

      Author's profile photo Stefan Grube
      Stefan Grube
      Blog Post Author

      The parameters should be:

      key.1 & value.1

      key.2 & value.2

      Author's profile photo Former Member
      Former Member

      Thanks Stefan! Able to post the stored value now.

       

      Regards,

      Pankaj

      Author's profile photo Olga Kaliada
      Olga Kaliada

      Hello Stefan,

      Thank you for helpful blog!

      One question

      Are you sure that namespace should be used there?

      DC1 key.1 write strDocNum Value
      DC1 value.1 module.strDocNum

      I tried with multiple keys and it works for REST adapter with the following configuration only

      DC1 key.1 write strDocNum Value1
      DC1 value.1 module.Value1
      DC1 key.2 write strDocNum Value2
      DC1 value.2 module.Value2

      Thank you!

      Author's profile photo Stefan Grube
      Stefan Grube
      Blog Post Author

      Hi Olga,

       

      Thank you for sharing your experience with REST adapter.

      I have not worked with REST adapter so far and this information is very useful for me.

       

      Regards

      Stefan

      Author's profile photo Luke Allen
      Luke Allen

      The module parameter is mentioned in SAP note 974481, example 6 & 7

      Author's profile photo Patrick Schaaf
      Patrick Schaaf

      Hi Stefan, Hi all,

      I have an Sync Interface called from ERP Proxy -> REST Receiver with Request / Response Mapping. I need to pass a value from the request to the response. I have tried it with your hints, but it fails. Apparently the Module is able to write, but not to read. Any help is welcome.

      I have also tried to put the Rest Adapter Bean into the middle with the same result. Also I have used RRB with ROB Bean, but as the Interface is already Sync i guess it is not needed.

      Stefan Grube 

      Any Idea?

      Author's profile photo Stefan Grube
      Stefan Grube
      Blog Post Author

      The parameters should be:

      key.1 & value.1

      key.2 & value.2

       

      The REST module should be in the middle

      Author's profile photo Patrick Schaaf
      Patrick Schaaf

      Thanks, that worked. I thought "value" is dynamic and should be replaced with the value of the dynamic object. Also i thought that key.2 & value.2 should be also "1" as the module should read the parameter written within DC1.

       

      Author's profile photo Stefan Grube
      Stefan Grube
      Blog Post Author

      My fault, you can use key.1 and value.1 for DC1 and DC2 both.

      But you can use different numbers as well.

      Author's profile photo Olga Gerlich
      Olga Gerlich

      Hi Stefan!

      I have to copy the value which can have dynamic amount of itself. DynamicConfigurationBean saves only last value. How can I save and read all values?

      My input:

      <Structure>
      <Position>
      <code>1</code>
      </Position>
      <Position>
      <code>2</code>
      </Position>
      </Structure>​

       

      Only "2" is saved

      My UDFs are identical to yours.Module%20in%20SFSF%20interface

      Module in SFSF interface

      Author's profile photo Stefan Grube
      Stefan Grube
      Blog Post Author

      It is not possible to save multiple entries in the dynamic configuration.
      I recommend concatenating your values into a single string with a delimiter that is not part of any string like this: 1|2

      Author's profile photo Keerthana Pagadala
      Keerthana Pagadala

      Hi Stefan,

       

      my request mapping is passthrough, can you let me know how can i acheive this?

       

      Regards,

      Keerthana