Skip to Content
Technical Articles
Author's profile photo Pavan Kumar Pothula

REST Look Up using UDF in SAP PO

Hello Experts,

I have read many blog posts for performing the REST Look up using Java mapping but I felt it would be helpful if we can achieve REST look up using UDF. Hence I have tried blogging one of the scenario where I have used REST Look up using UDF.

 

Scenario: We have a scenario where a field ‘Code’ value has to be checked in the target system for its existence.  Based on its existence I have to pass the value “True” if it exits else I have to pass “False” in my UDF.

 

Step1: Create a receiver communication channel for your look up using REST adapter.

Communication Channel : CC_LookupChannel_REST

Create a Message type to receive your response message through the lookup channel and assign the message type in the Element name and its namespace respectively.

Step2: Create your Message mapping as required and pass the required source fields to the UDF as inputs. In my case I have passed a value ID and Bussiness Component and Lookup Channel Names as inputs to the UDF.

Step3: Create the UDF in your message mapping using the below code.

Here I am passing business component and Lookup channels as inputs which are passed using parameterized mapping.

 

Parameterized Mapping Values:

Following Parameterized values are to be passed from your ICO/IFLOW.

Lookup Channel Name(ChannelName): CC_LookupChannel_REST

Business Component: BC_Target

 

Code:

public void RESTLookup(String[] var1, String[] BusinessComponent, String[] ChannelName, ResultList result, Container container) throws StreamTransformationException{

 

AbstractTrace trace = container.getTrace();
String floc=””;
try{

Channel channel= LookupService.getChannel(BusinessComponent[0],ChannelName[0]);

SystemAccessor accessor = LookupService. getSystemAccessor(channel);

// Look up service xml

String RestXML = “<?xml version=\”1.0\” encoding=\”UTF-8\”?><ns2:MT_RESTIN_V01 xmlns:ns2=\”urn:std:restlookup”><Equipment><Code>”+var1[0]+”</Code></Equipment></ns2:MT_RESTIN_V01>”;

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

XmlPayload payload = LookupService.getXmlPayload(inputStream);

Payload RESTOutPayload = null;

RESTOutPayload = accessor.call(payload);

InputStream inps = RESTOutPayload.getContent();

DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();

DocumentBuilder builder = factory.newDocumentBuilder();
Document document = builder.parse(inps);

NodeList list = document.getElementsByTagName(“Code”);
Node node = list.item(0);
if (node != null) {
//result.addValue( “True”);
//floc = node.getNodeValue();
node = node.getFirstChild();
if (node != null) {
floc = node.getNodeValue();
//result.addValue(floc);

}
}

}catch (Exception e) {
}

if(floc.equals(var1[0]))
{
result.addValue( “True”);
}
else
{
result.addValue( “False”);
}

}

 

Hope this will be helpful 🙂

Thanks,

Pavan Kumar P

Reference Blog posts:

https://blogs.sap.com/2015/09/11/yes-rest-lookup-is-possible-in-pi/

https://blogs.sap.com/2013/08/07/how-to-soap-lookup/

 

Assigned Tags

      3 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Bhargava krishna Talasila
      Bhargava krishna Talasila

      Nice blog.  Thanks

      Author's profile photo Pavan Kumar
      Pavan Kumar
      Blog Post Author

      Thanks Bhargava Krishna.

       

      Author's profile photo Yunze Wang
      Yunze Wang

      Hi Pavan Kumar,

      I use ASMA instead of  xpath substitution,I set ASMA in UDF before call lookup channel,but when using it in channel,the channel didn't get the ASMA values,but it did showup in the payload of dynamic configuration,how come?

      Kind Regards

      yunze