Skip to Content

Have you ever wondered how to configure the receivers dynamically at run time when the input is a complex flat file which can not be converted to XML file? Yes it is possible. We can use JAVA mapping using DOM parser to achieve this.

 

  1. Create a JAVA Mapping using DOM parser to create the Receiver List dynamically
  2. Create Enhanced Receiver Determination with Interface mapping which refers to the JAVA mapping created in step 1.

 

Step1:

To create a receiver list dynamically we need to use the standard Message Type named “Receivers”. The message type “Receivers” is available under SCV “SAP BASIS” and namespace “http://sap.com/xi/XI/System”.

 

 

image

 

Inside JAVA Mapping we will use the DOM parser to create the desired structure of “Receivers” and also to populate the values in the field “Service”.

 

The sample java code using DOM parser is given below.

package SR_SAP2VAN_RD_Package;

 

import java.io.BufferedReader;

import java.io.BufferedWriter;

 

import java.io.InputStream;

import java.io.InputStreamReader;

import java.io.OutputStream;

import java.io.OutputStreamWriter;

import java.util.HashMap;

import java.util.Map;

 

 

import com.sap.aii.mapping.api.StreamTransformationConstants;

import com.sap.aii.mapping.api.StreamTransformation;

import com.sap.aii.mapping.api.StreamTransformationException;

 

import javax.xml.parsers.DocumentBuilder;

import javax.xml.parsers.DocumentBuilderFactory;

 

import javax.xml.transform.Transformer;

import javax.xml.transform.TransformerFactory;

import javax.xml.transform.dom.DOMSource;

import javax.xml.transform.stream.StreamResult;

 

 

import org.w3c.dom.Document;

import org.w3c.dom.Element;

import org.w3c.dom.Text;

 

 

 

 

public class SR_SAP2VAN_RD_Class implements StreamTransformation {

private Map param = null;

public void setParameter (Map param) {

this.param = param;

if (param == null) {

this.param = new HashMap();

}

}

public void execute(InputStream inStream, OutputStream

outStream) throws StreamTransformationException

{

     

try{

 

BufferedReader in = new BufferedReader(new InputStreamReader(inStream));

BufferedWriter out = new BufferedWriter(new      OutputStreamWriter(outStream));

 

 

DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();

DocumentBuilder builder = factory.newDocumentBuilder();

 

 

// Create the output DOM

 

Document docOut = builder.newDocument();

 

Element node1 = docOut.createElement(“Receivers”);

docOut.appendChild(node1);

 

node1.setAttribute(“xmlns”, “http://sap.com/xi/XI/System“);

                 

String strLine;

String File_in_1,File_in_2,File_out_1,File_out_2;

int Flag = 0;

 

   

String senderService = (String) param.get(StreamTransformationConstants.SENDER_SERVICE);

    

while ((strLine = in.readLine()) != null)

 

{

if ((strLine.substring(0,7)).equals(“E2EDL24”) && Flag == 0)

{

if ((strLine.substring(199,203)).equals(“BR18”) || (strLine.substring(199,203)).equals(“BR1F”) )

{

                 

Element node2 = docOut.createElement(“Receiver”);

node1.appendChild(node2);

                                                           

Element node3 = docOut.createElement(“Service”);

node2.appendChild(node3);

                                         

if (senderService.equals(“BS_SAP_D”))

{

Text node3_1Text = docOut.createTextNode(“BS_SAP_D”);

node3.appendChild(node3_1Text);                                                                

}

if (senderService.equals(“BS_SAP_Q”))

{

Text node3_2Text = docOut.createTextNode(“BS_SAP_Q”);

node3.appendChild(node3_2Text);                                                                

}                                                          

if (senderService.equals(“BS_SAP_P”))

{

Text node3_3Text = docOut.createTextNode(“BS_SAP_P”);

node3.appendChild(node3_3Text);                                                                

}

                                         

Element node4 = docOut.createElement(“Receiver”);

node1.appendChild(node4);

                 

Element node5 = docOut.createElement(“Service”);

node4.appendChild(node5);

 

if (senderService.equals(“BS_SAP_D”))

{

Text node5_1Text = docOut.createTextNode(“BS_VAN_D”);

node5.appendChild(node5_1Text);                                                                

}

if (senderService.equals(“BS_SAP_Q”))

{

Text node5_2Text = docOut.createTextNode(“BS_VAN_Q”);

node5.appendChild(node5_2Text);                                                                

}                                                          

if (senderService.equals(“BS_SAP_P”))

{

Text node5_3Text = docOut.createTextNode(“BS_VAN_P”);

node5.appendChild(node5_3Text);                                                                

}

                                                     

                                                                             

Flag = 1;

}

else

{

      Element node6 = docOut.createElement(“Receiver”);

node1.appendChild(node6);

                 

Element node7 = docOut.createElement(“Service”);

node6.appendChild(node7);

 

Text node7Text = docOut.createTextNode(“Business_Service_SAP”);

node7.appendChild(node7Text);

Flag = 1;

}

     

}

 

}   

 

if (Flag == 0)

{

Element node6 = docOut.createElement(“Receiver”);

node1.appendChild(node6);

                 

Element node7 = docOut.createElement(“Service”);

node6.appendChild(node7);

 

Text node7Text = docOut.createTextNode(“Business_Service_SAP”);

node7.appendChild(node7Text);

Flag = 1;

}

                       

                                                     

// transform the new xml to the output stream

TransformerFactory tf = TransformerFactory.newInstance();

Transformer transform = tf.newTransformer();

transform.transform(new DOMSource(docOut), new StreamResult(out));

}

 catch (Exception e)

{

  e.printStackTrace();

}

   

}

}

 

We need to import the library “aii_map_api.jar” in our JAVA package “SR_SAP2VAN_RD_Package”.

The jar file is available in the following XI server folders

“j2ee\cluster\server0\apps\sap.com\com.sap.xi.services”

 

The above java mapping will build receivers dynamically based on input file.

 

In Integration Repository, we have to import the JAVA mapping as an Imported Archive.

 

 

image

 

Now we have to create an Interface Mapping for it.

 

image

Step 2:

In Receiver determination, choose the type of Receiver determination as “Extended” and then use the interface mapping created in step 1.

 

 

image

To report this post you need to login first.

2 Comments

You must be Logged on to comment or reply to a post.

    1. Madan Mohan Agrawal Post author
      Thanks Daniel, Now I got to know another way to achieve the mapping apart from DOM parser and SAX parser.

      Groovy seems to be interesting and I would surely take some time to learn this also.

      This blog describes how to create receivers dynamically using DOM parser, and since the numbers of receivers are few so I have used the DOM parser. Anyway its good to know more solutions to a single requirement.

      Regards,
      Madan Agrawal

      (0) 

Leave a Reply