Showing results for 
Search instead for 
Did you mean: 

Soap lookup in SAP PI

0 Kudos

Hello Expert

I have requirement for IDOC to webs-service  for third pty system , There is two things :

1> I will trigger the data from Idoc  and target is a web service . between mapping i will use  a SOAP Lookup .This lookup call a web service ,In this web service 3 input parameter .

a . Email address   b .password  c .ClientApplicationIdentifier.

and after pass three parameter we get two  response parameter example

a.ServiceUrl>https://Rounting service

b> QueryServiceUrl >https://Query service .

Query service is my final target url .using this service we will send the data to target system.

Please let me know how i can use  soap lookup ,.Only jdbc lookup and RFC lookup in SAP PI . Can you provide me a java code for this lookup .



View Entire Topic
Active Contributor
0 Kudos

Hi Pankaj!

Here is example java code  where SOAP lookup is performed. You can use it as template for your own code.

public class CustomSOAPLookup extends AbstractTransformation {

     private String soapChannel;

     private String businessSystem;

     public void transform(TransformationInput inMessage, TransformationOutput outMessage) throws StreamTransformationException{

          soapChannel = inMessage.getInputParameters().getString("SOAP_LOOKUP_CHANNEL");

          businessSystem = inMessage.getInputParameters().getString("B_SYSTEM");

          this.executeMapping(inMessage.getInputPayload().getInputStream(), outMessage.getOutputPayload().getOutputStream());


     public void executeMapping(InputStream in, OutputStream out) throws StreamTransformationException {

          AbstractTrace trace = getTrace();

          try {

               trace.addInfo("Transformation started");

               DocumentBuilderFactory bldFactory=DocumentBuilderFactory.newInstance();



               DocumentBuilder docBuilder = bldFactory.newDocumentBuilder();

               DocumentBuilder docrespBuilder = bldFactory.newDocumentBuilder();

               Document inputDoc = docBuilder.parse(in);

               Element docRoot = inputDoc.getDocumentElement();

               NamedNodeMap attr = docRoot.getElementsByTagName("Action").item(0).getAttributes();

               String actionID = attr.getNamedItem("id").getNodeValue();

               trace.addInfo("Building DOM result");

               DOMSource domSource = new DOMSource(inputDoc);

               StringWriter writer = new StringWriter();

               StreamResult result = new StreamResult(writer);

               TransformerFactory tf = TransformerFactory.newInstance();

               Transformer transformer = tf.newTransformer();

               transformer.transform(domSource, result);

               String payloadXML = writer.toString();

               String encodedData = DatatypeConverter.printBase64Binary(payloadXML.getBytes());

               String requestXML = "<ns:ActionImport_ImportActions xmlns:ns=\"ns_sap\"><ns:ImportAction><ns:XMLData>" +

  encodedData + "</ns:XMLData></ns:ImportAction></ns:ActionImport_ImportActions>";

               Channel channel = LookupService.getChannel(businessSystem,soapChannel);

               trace.addInfo("Channel created");

               SystemAccessor accessor = LookupService.getSystemAccessor(channel);

               trace.addInfo("Got accessor");

               InputStream inputStream = new ByteArrayInputStream(requestXML.getBytes());

               XmlPayload payload = LookupService.getXmlPayload(inputStream);


               Payload responsePayload = null;


               trace.addInfo("Performing SOAP request");

               responsePayload =;


               InputStream inp = responsePayload.getContent();

               Document responseDoc = docrespBuilder.parse(inp);

               Element respDocRoot = responseDoc.getDocumentElement();


               String responseXML = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><ns0:Messages xmlns:ns0=\"\"><Message1>";

               Element elReturn = (Element)respDocRoot.getElementsByTagNameNS("ns_sap", "return").item(0);

               NodeList resultsList = elReturn.getElementsByTagNameNS("ns_sap", "result");


               for (int i=0; i < resultsList.getLength(); ++i) {

                    Node resultNode = resultsList.item(i);

                    responseXML = responseXML + "<GroupResult>";

                    responseXML = responseXML + "<Id>" + actionID + "</Id>";


                    NodeList resultContents = resultNode.getChildNodes();

                    for (int j=0; j < resultContents.getLength(); ++j) {

                         Node resultContent = resultContents.item(j);

                         if (resultContent.getNodeType() == Node.ELEMENT_NODE) {

                              String nodeName = resultContent.getLocalName();     

                              if (nodeName.equalsIgnoreCase("name"))

                                   responseXML = responseXML + "<Name>" + resultContent.getTextContent() + "</Name>";

                              else if (nodeName.equalsIgnoreCase("errorCode"))

                                   responseXML = responseXML + "<Code>" + resultContent.getTextContent() + "</Code>";

                              else if (nodeName.equalsIgnoreCase("errorMessage"))

                                   responseXML = responseXML + "<Message>" + resultContent.getTextContent().replaceAll("\\s+", " ").trim() + "</Message>";



                    responseXML = responseXML + "</GroupResult>";


               responseXML = responseXML + "</Message1></ns0:Messages>";



          catch (Exception e) {

               trace.addWarning("Error during transformation: " + e);




Regards, Evgeniy.

Active Contributor
0 Kudos

Adding to Eve comment,You can refer the below link as well.

0 Kudos

HI Evgeniy Kolmakov

Thanks for your response .

As per RFC and JDBC lookup  we need a parameterzied mapping and binding the communication channel in Message mapping and Operation  mapping . So same process we need in SOAP lookup also .? And can you please share the any doc with screen short for this end to end SOAP Lookup process.


panakaj Singh

Active Contributor
0 Kudos

Hi Pankaj!

I'm not sure if I could provide you any document about SOAP lookup process apart from java code I've posted above. But I think that it's not necessary. Just define String parameters for business system and channel name in your operation mapping and bind it to java mapping input parameters. Your java mapping should take input payload, perform SOAP lookup and build target message structure, defined in your operation mapping.

Regards, Evgeniy.