Parsing in RFC lookup
Hi All,
I have wriiten a RFC lookup for mapping the company code. But I am not getting the result while parsing the XML. I have tested the code and without parsing I am getting the correct value in XML. Can anybody send the code for parsing the XML data using DOM.
Below is the code which I am using .
try {
docResponse = builder.parse(in);
if (docResponse == null) {
importanttrace.addWarning("docResponse is null");
res = docResponse.getElementsByTagName("COMPANYID").item(0).getFirstChild().getNodeValue();
if (res == null) {
importanttrace.addWarning("res is null");
catch (Exception e) {
importanttrace.addWarning("Error when parsing RFC Response - " + e.getMessage());
try {
// Free resources, close the accessor..
if (accessor != null) {
try {
accessor.close();
} catch (LookupException e) {
importanttrace.addWarning( "Error while closing accessor " + e.getMessage());
} catch (Exception e) {
importanttrace.addWarning("Result value not found in DOM - " + e);
// return the result obtained above
return res;
Thanks,
Aparna
Maybe it's really just the typo in your element name and everything works fine when you use:
res = docResponse.getElementsByTagName("COMPANY_CODE").item(0).getFirstChild().getNodeValue();
And I think method <em>getTextContent()</em> should also do the trick of the two calls you're using:
res = docResponse.getElementsByTagName("COMPANY_CODE").item(0).getTextContent();
Similar Messages
-
RFC Lookup - Best Approach To Parse Returned Tables
Hi Everyone,
We are doing some RFC Lookups at a header node that are returning tables for all of the items (for performance reasons). I am trying to figure out what the best way to extract the values from the table, which is most of time has more than 1 key column. At the moment I am doing this through DOM, but I have also heard about using arrays, and have even seen an example of using a hashtables with all of the values concatenated together to later parse out using substrings. I'm looking for the best approach to:
1) Store this data as some kind of global object to lookup during the header
2) Search and Parse from the global object during linte items.
As an example, I have the following lines in my table:
Key1,Key2,Value1,Value2,Value3
A,A,1,2,3
A,B,1,2,4
A,C,3,4,2
B,A,2,4,6
And during line item processing I may want to find the value for Key1=A, Key2=C.
Thanks
PeterHi Peter,
Please take a look at these...
https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/xi/xi-code-samples/xi%20mapping%20lookups%20rfc%20api.pdf
/people/siva.maranani/blog/2005/08/23/lookup146s-in-xi-made-simpler
/people/sravya.talanki2/blog/2005/12/21/use-this-crazy-piece-for-any-rfc-mapping-lookups
/people/alessandro.guarneri/blog/2006/03/27/sap-xi-lookup-api-the-killer
cheers,
Prashanth
P.S Please mark helpful answers -
Hi,
I am performing RFC lookup using Communication Channel.
I have used a function called "Z_MATERIAL_DETAILS".
Input to this function is "MATERIALID" and Output of the function is "MATNR".
I am using the following code in my UDF for performing lookup::
//write your code here
final String CHANNEL_NAME = "CC_RFC_LookUp",
VALNOTFOUND = "VALUE_NOT_FOUND",
SAPRFCNS = "urn:sap-com:document:sap:rfc:functions",
TAG_FM = "Z_MATERIAL_DETAILS",
// TAG_QTB = "QUERY_TABLE",
TAG_QFL = "UOMCODE"; //UOMCODE
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = null;
factory.setNamespaceAware(false);
factory.setValidating(false);
try {
builder = factory.newDocumentBuilder();
} catch (Exception e) {
// trace.addWarning("Error creating DocumentBuilder - " + e.getMessage());
result.addValue(e.toString());
Document docReq = null;
try {
// Building up RFC Request Document
docReq = builder.newDocument();
Node root = docReq.appendChild(docReq.createElementNS(SAPRFCNS, TAG_FM));
root.appendChild(docReq.createElement(TAG_QFL)).appendChild(docReq.createTextNode(resultFieldName[0]));
} catch (Exception e) {
// trace.addWarning("Error while building RFC Request - " + e);
result.addValue(e.toString());
// trace.addInfo("RFC Request XML: " + docReq.toString());
// Lookup
Payload result1 = null;
try {
Channel channel = LookupService.getChannel("EC1CLNT800", "CC_RFC_LookUp");
RfcAccessor accessor = LookupService.getRfcAccessor(channel);
InputStream is = new ByteArrayInputStream(docReq.toString().getBytes());
XmlPayload payload = LookupService.getXmlPayload(is);
result1 = accessor.call(payload);
} catch (LookupException e) {
// trace.addWarning("Error during lookup - " + e);
result.addValue(e.toString());
// Parsing RFC Response Document
Document docRsp = null;
try {
docRsp = builder.parse(result1.getContent());
} catch (Exception e) {
// trace.addWarning("Error when parsing RFC Response - " + e.getMessage());
result.addValue(e.toString());
//trace.addInfo("RFC Response XML: " + docRsp.toString());
String res = "";
try {
res = docRsp.getElementsByTagName("UOMTEXT").item(0).getFirstChild().getNodeValue();
} catch (Exception e) {
// trace.addWarning("Result value not found in DOM - " + e.getMessage());
result.addValue(e.toString()+VALNOTFOUND);
result.addValue(res);
Code in Z_MATERIAL_DETAILS ::
""Local Interface:
*" IMPORTING
*" VALUE(UOMCODE) LIKE MARA-MFRPN OPTIONAL
*" EXPORTING
*" VALUE(UOMTEXT) LIKE MARA-MATNR
*" EXCEPTIONS
*" val_not_found
<b>select single matnr from mara into uomtext where mfrpn = uomcode.</b>
if sy-subrc <> 0.
raise val_not_found.
endif.
ENDFUNCTION.
<b>When i send three material ids the function module will access the R/3 system thrice which will give rise to PERFORMANCE ISSUE.
So,is there any way to send all the materialids at one time to Function module and similarly receive all the MATNR from Function at once,so that we need to access R/3 system only once.</b>HI,
Check this link for passing table parameter in JCO call.
http://www.sapdevelopment.co.uk/java/jco/jco_callfunc.htm
Following is the code for retrieving table parameter in JCO call to function BAPI_PO_CREATE.
JCO.Table return_tab = function.getTablesParameterList().getTable("RETURN");
if (return_tab.getNumRows()) > 0 {
// Output the error messages
return_tab.firstRow();
do {
System.out.println(return_tab.getString("MESSAGE");
while (return_tab.nextRow());
} else {
String PO_NUM = function.getExportParametersList().getString("PURCHASEORDER");
System.out.println("Purchase order " + PO_NUM + " created");
Thanks and Regards,
Sandeep Maurya. -
Java Error in RFC Lookup in XSLT Mapping usinf Java helper class
Hi All,
I am doing RFC Lookup in XSLT Mapping using Java Helper class.
The Lookup works fine when called one RFC at a time However my requirement is I want to do 2 Lookups.
Both Lookups works when done individually however when I call both lookups in one mapping I get following error "javax.xml.transform.TransformerException: DOMSource whose Node is null."
Following is the code I have written in XSLT for the lookup:
<xsl:template name="Lookup_1">
<xsl:param name="STDPN"/>
<rfc:RFC_READ_TABLE>
<QUERY_TABLE>KNA1</QUERY_TABLE>
<OPTIONS><item><TEXT>
<xsl:value-of select="$STDPN"/>
</TEXT></item>
</OPTIONS>
<FIELDS>
<item>
<FIELDNAME>KUNNR</FIELDNAME>
</item>
</FIELDS>
</rfc:RFC_READ_TABLE>
</xsl:variable>
<xsl:variable name="response" xmlns:lookup="java:urn.mt.pi" select="lookup:execute($request, 'BS_D, 'cc_RfcLookup', $inputparam)"/>
<xsl:element name="STDPN">
<xsl:value-of select="$response//DATA/item/WA"/>
</xsl:element>
</xsl:template>
<xsl:template name="Lookup_2">
<xsl:param name="BELNR"/>
<xsl:variable name="Query">AGMNT = '<xsl:value-of select="$BELNR"/>'</xsl:variable>
<xsl:variable name="request1">
<rfc:RFC_READ_TABLE>
<QUERY_TABLE>ZTABLE</QUERY_TABLE>
<OPTIONS><item><TEXT>
<xsl:value-of select="$Query"/>
</TEXT></item>
</OPTIONS>
<FIELDS>
<item>
<FIELDNAME>KUNAG</FIELDNAME>
</item>
</FIELDS>
</rfc:RFC_READ_TABLE>
</xsl:variable>
<xsl:variable name="response1" xmlns:lookup="java:urn.mt.pi" select="lookup:execute($request1, 'BS_D','cc_RfcLookup', $inputparam)"/>
<xsl:element name="BELNR">
<xsl:value-of select="$response1//DATA/item/WA"/>
</xsl:element>
</xsl:template>
My Question: Am I doing anything wrong? Or Is it possible to call multiple lookups in one XSLT?
Thanks and Regards,
AtulHi Atul,
I had the same problem like you had.
The main Problem is that with the example code the request variable is created as NodeList object. In XSLT a variable is somekind of a constant and can't be changed. As the request object is empty after the first request the programm fails at the following line:
Source source = new DOMSource(request.item(0));
So I've created a workaround for this problem.
In the call of the template I've put the request as a parameter object at the template call:
<xsl:with-param name="req">
<rfc:PLM_EXPLORE_BILL_OF_MATERIAL xmlns:rfc="urn:sap-com:document:sap:rfc:functions">
<APPLICATION>Z001</APPLICATION>
<FLAG_NEW_EXPLOSION>X</FLAG_NEW_EXPLOSION>
<MATERIALNUMBER><xsl:value-of select="value"/></MATERIALNUMBER>
<PLANT>FSD0</PLANT>
<VALIDFROM><xsl:value-of select="//Recordset/Row[name='DTM-031']/value"/></VALIDFROM>
<BOMITEM_DATA/>
</rfc:PLM_EXPLORE_BILL_OF_MATERIAL>
</xsl:with-param>
With this change the request will be provided as a String object and not as a NodeList object.
Afterwards the RfcLookup.java has to be changed to the following:
package com.franke.mappings;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.Map;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.Source;
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.Node;
import org.w3c.dom.NodeList;
import com.sap.aii.mapping.lookup.Channel;
import com.sap.aii.mapping.api.StreamTransformationConstants;
import com.sap.aii.mapping.api.AbstractTrace;
import com.sap.aii.mapping.lookup.RfcAccessor;
import com.sap.aii.mapping.lookup.LookupService;
import com.sap.aii.mapping.lookup.XmlPayload;
* @author Thorsten Nordholm Søbirk, AppliCon A/S
* Helper class for using the XI Lookup API with XSLT mappings for calling RFCs.
* The class is generic in that it can be used to call any remote-enabled
* function module in R/3. Generation of the XML request document and parsing of
* the XML response is left to the stylesheet, where this can be done in a very
* natural manner.
* TD:
* Changed the class that request is sent as String, because of IndexOutOfBound-exception
* When sending multiple requests in one XSLT mapping.
public class RfcLookup {
* Execute RFC lookup.
* @param request RFC request - TD: changed to String
* @param service name of service
* @param channelName name of communication channel
* @param inputParam mapping parameters
* @return Node containing RFC response
public static Node execute( String request,
String service,
String channelName,
Map inputParam)
AbstractTrace trace = (AbstractTrace) inputParam.get(StreamTransformationConstants.MAPPING_TRACE);
Node responseNode = null;
try {
// Get channel and accessor
Channel channel = LookupService.getChannel(service, channelName);
RfcAccessor accessor = LookupService.getRfcAccessor(channel);
// Serialise request NodeList - TD: Not needed anymore as request is String
/*TransformerFactory factory = TransformerFactory.newInstance();
Transformer transformer = factory.newTransformer();
Source source = new DOMSource(request.item(0));
ByteArrayOutputStream baos = new ByteArrayOutputStream();
StreamResult streamResult = new StreamResult(baos);
transformer.transform(source, streamResult);*/
// TD: Add xml header and remove linefeeds for the request string
request = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"+request.replaceAll("[\r\n]+", "");
// TD: Get byte Array from request String to send afterwards
byte[] requestBytes = request.getBytes();
// TD: Not used anymore as request is String
//byte[] requestBytes = baos.toByteArray();
trace.addDebugMessage("RFC Request: " + new String(requestBytes));
// Create input stream representing the function module request message
InputStream inputStream = new ByteArrayInputStream(requestBytes);
// Create XmlPayload
XmlPayload requestPayload =LookupService.getXmlPayload(inputStream);
// Execute lookup
XmlPayload responsePayload = accessor.call(requestPayload);
InputStream responseStream = responsePayload.getContent();
TeeInputStream tee = new TeeInputStream(responseStream);
// Create DOM tree for response
DocumentBuilder docBuilder =DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document document = docBuilder.parse(tee);
trace.addDebugMessage("RFC Response: " + tee.getStringContent());
responseNode = document.getFirstChild();
} catch (Throwable t) {
StringWriter sw = new StringWriter();
t.printStackTrace(new PrintWriter(sw));
trace.addWarning(sw.toString());
return responseNode;
* Helper class which collects stream input while reading.
static class TeeInputStream extends InputStream {
private ByteArrayOutputStream baos;
private InputStream wrappedInputStream;
TeeInputStream(InputStream inputStream) {
baos = new ByteArrayOutputStream();
wrappedInputStream = inputStream;
* @return stream content as String
String getStringContent() {
return baos.toString();
/* (non-Javadoc)
* @see java.io.InputStream#read()
public int read() throws IOException {
int r = wrappedInputStream.read();
baos.write(r);
return r;
Then you need to compile and upload this class and it should work.
I hope that this helps you.
Best regards
Till -
I have written RFC Lookup.
But I am getting the belows errors
/usr/sap/XPD/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Map1f873e902d6811df9e460017a451d38e/source/com/sap/xi/tf/_MM_RFCLookup_.java:3: <identifier> expected import com.sap.aii.mappingtool.tf3.;import com.sap.aii.mappingtool.tf3.rt.;import java.util.;import java.io.; import java.lang.reflect.;import java.io.InputStream;import javax.xml.parsers.DocumentBuilder;import java.util.Iterator;import com.sap.aii.mapping.api.AbstractTrace;import java.util.Map;import org.w3c.dom.;import javax.xml.parsers.DocumentBuilderFactory;import import;import java.io.ByteArrayInputStream;import com.sap.aii.mapping.lookup.; ^ /usr/sap/XPD/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Map1f873e902d6811df9e460017a451d38e/source/com/sap/xi/tf/_MM_RFCLookup_.java:3: '.' expected import com.sap.aii.mappingtool.tf3.;import com.sap.aii.mappingtool.tf3.rt.;import java.util.;import java.io.; import java.lang.reflect.;import java.io.InputStream;import javax.xml.parsers.DocumentBuilder;import java.util.Iterator;import com.sap.aii.mapping.api.AbstractTrace;import java.util.Map;import org.w3c.dom.;import javax.xml.parsers.DocumentBuilderFactory;import import;import java.io.ByteArrayInputStream;import com.sap.aii.mapping.lookup.; ^ /usr/sap/XPD/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Map1f873e902d6811df9e460017a451d38e/source/com/sap/xi/tf/_MM_RFCLookup_.java:119: 'try' without 'catch' or 'finally' try { ^ /usr/sap/XPD/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Map1f873e902d6811df9e460017a451d38e/source/com/sap/xi/tf/_MM_RFCLookup_.java:130: illegal start of type } catch (Exception e) { ^ /usr/sap/XPD/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Map1f873e902d6811df9e460017a451d38e/source/com/sap/xi/tf/_MM_RFCLookup_.java:135: <identifier> expected trace.addInfo("RFC Request XML: " + docReq.toString()); ^ /usr/sap/XPD/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Map1f873e902d6811df9e460017a451d38e/source/com/sap/xi/tf/_MM_RFCLookup_.java:139: illegal start of type try { ^ /usr/sap/XPD/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Map1f873e902d6811df9e460017a451d38e/source/com/sap/xi/tf/_MM_RFCLookup_.java:151: <identifier> expected Document docRsp = null; ^ /usr/sap/XPD/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Map1f873e902d6811df9e460017a451d38e/source/com/sap/xi/tf/_MM_RFCLookup_.java:152: illegal start of type try { ^ /usr/sap/XPD/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Map1f873e902d6811df9e460017a451d38e/source/com/sap/xi/tf/_MM_RFCLookup_.java:167: <identifier> expected trace.addInfo("RFC Response XML: " + docRsp.toString()); ^ /usr/sap/XPD/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Map1f873e902d6811df9e460017a451d38e/source/com/sap/xi/tf/_MM_RFCLookup_.java:170: illegal start of type try { ^ /usr/sap/XPD/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Map1f873e902d6811df9e460017a451d38e/source/com/sap/xi/tf/_MM_RFCLookup_.java:176: <identifier> expected return res; ^ /usr/sap/XPD/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Map1f873e902d6811df9e460017a451d38e/source/com/sap/xi/tf/_MM_RFCLookup_.java:181: 'class' or 'interface' expected public static void main(String[] args) throws Exception{/!_$ClNRep_/_MM_RFCLookup_ st = new /!_$ClNRep_/_MM_RFCLookup_(); st.testExecute(); } ^ /usr/sap/XPD/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Map1f873e902d6811df9e460017a451d38e/source/com/sap/xi/tf/_MM_RFCLookup_.java:182: 'class' or 'interface' expected } ^ /usr/sap/XPD/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Map1f873e902d6811df9e460017a451d38e/source/com/sap/xi/tf/_MM_RFCLookup_.java:183: 'class' or 'interface' expected
Can someone please help to resolve this issueHello Satish,
Here is my complete code
final String CHANNEL_NAME = "cc_Rfc_Receiver_Lookup",
SERVICE = "Sys_EPD_110" ,
VALNOTFOUND = "VALUE_NOT_FOUND",
SAPRFCNS = "urn:sap-com:document:sap:rfc:functions",
TAG_FM = "Z_COMPARE_ADDRESS",
TAG_RES = "E_FLAG",
TAG_I_ALLIANCEID = "I_ALLIANCEID",
//TAG_I_OVRDFLAG = "I_OVRDFLAG",
TAG_I_PSTLZ = "I_PSTLZ",
TAG_I_CITY1 = "I_CITY1",
TAG_I_STATE = "I_STATE",
TAG_I_COUNTRY = "I_COUNTRY";
MappingTrace trace;
trace = container.getTrace();
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = null;
factory.setNamespaceAware(false);
factory.setValidating(false);
try {
builder = factory.newDocumentBuilder();
} catch (Exception e) {
trace.addWarning("Error creating DocumentBuilder - " + e.getMessage());
return null;
Document docReq = null;
try {
// Building up RFC Request Document
docReq = builder.newDocument();
Node root = docReq.appendChild(docReq.createElementNS(SAPRFCNS, TAG_FM));
root.appendChild(docReq.createElement(TAG_I_ALLIANCEID)).appendChild(docReq.createTextNode(I_ALLIANCEID));
//root.appendChild(docReq.createElement(TAG_I_OVRDFLAG)).appendChild(docReq.createTextNode(I_OVRDFLAG));
root.appendChild(docReq.createElement(TAG_I_PSTLZ)).appendChild(docReq.createTextNode(I_PSTLZ));
root.appendChild(docReq.createElement(TAG_I_CITY1)).appendChild(docReq.createTextNode(I_CITY1));
root.appendChild(docReq.createElement(TAG_I_STATE)).appendChild(docReq.createTextNode(I_STATE));
root.appendChild(docReq.createElement(TAG_I_COUNTRY)).appendChild(docReq.createTextNode(I_COUNTRY));
} catch (Exception e) {
trace.addWarning("Error while building RFC Request - " + e);
return null;
trace.addInfo("RFC Request XML: " + docReq.toString());
// Lookup
Payload result = null;
try {
Channel channel = LookupService.getChannel(SERVICE, CHANNEL_NAME);
RfcAccessor accessor = LookupService.getRfcAccessor(channel);
InputStream is = new ByteArrayInputStream(docReq.toString().getBytes());
XmlPayload payload = LookupService.getXmlPayload(is);
result = accessor.call(payload);
} catch (LookupException e) {
trace.addWarning("Error during lookup - " + e);
return null;
// Parsing RFC Response Document
Document docRsp = null;
try {
docRsp = builder.parse(result.getContent());
} catch (Exception e) {
trace.addWarning("Error when parsing RFC Response - " + e.getMessage());
return null;
trace.addInfo("RFC Response XML: " + docRsp.toString());
String res = "";
try {
res = docRsp.getElementsByTagName(TAG_RES).item(0).getNodeValue();
} catch (Exception e) {
trace.addWarning("Result value not found in DOM - " + e);
return VALNOTFOUND;
return res;
The Output of this RFC lookup is
<RFC Response XML: <rfc:Z_COMPARE_ADDRESS.Response xmlns:rfc="urn:sap-com:document:sap:rfc:functions"> <E_FLAG>Y</E_FLAG> </rfc:Z_COMPARE_ADDRESS.Response>
But the field value shows null
Thanks -
Hi guys,
I am using RFC API to perform some lookups from within my mapping program.
In order to create the request in XML, I am using DOM xml parser.
My code works fine when input data is in English, but when it is in another language, e.g. Greek, input data is respresented wrongly in XML document.
The ppiece of code where I create the XML request is the following:
Document docReq = null;
// Building up RFC Request Document
docReq = builder.newDocument();
RFCInterfaceLine il = null;
Element documentElement = docReq.createElement("ns0:" + remoteFunctionName);
documentElement.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:ns0", "urn:sap-com:document:sap:rfc:functions");
Node root = docReq.appendChild(documentElement);
rfcInterfaceParametersLines = rfcInterfaceParameters.getLines();
for (int i = 0; i < functionParameters.size(); i++)
il = (RFCInterfaceLine) rfcInterfaceParametersLines.get(i);
if (il.getParameterType().equalsIgnoreCase("I"))
root.appendChild(docReq.createElement(il.getParameterName())).appendChild(docReq.createTextNode((String) functionParameters.get(i)));
RFCInterfaceLine is a class used to represent the parameters (inputs, outputs and exceptions) used by the Remote Function Module in ABAP. "I" stands for Import. So when I have an import parameter, I create an element in XML.
However, in the final XML document I cannot see as a header the encoding = "UTF" attribute. Is this the one that is missing to enable other languages as well??
EvaggelosHi refer these
If you want to use DOM, you'll also have to choose a parser, since DOM's specification doesn't specify a parser, just document and element handlers, so there are various implementations of parsers for DOM. I've used Xerces's DOMParser (org.apache.xerces.parsers.DOMParser) on Java Mappings with success (never tried on UDF, though) and it's very simple.
After you get the output stream from the rfc lookup, just use:
DOMParser parser = new DOMParser();
InputSource input = new InputSource(in);
parser.parse(input);
Document MyDoc = parser.getDocument();
to get the Document object. Then you can use regular DOM methods to get the value.
For example, with
String value = MyDoc.getDocumentElement().getFirstChild().getNodeValue();
you'd get the value of the first child of the root element.
following document on XI Mapping lookups RFC API by Michal?
https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/xi/xi-code-samples/xi%20mapping%20lookups%20rfc%20api.pdf
Mapping lookups u0096 RFC API
<b>Mapping Lookups (New)</b>
http://help.sap.com/saphelp_erp2005/helpdata/en/0f/f084429fb4aa1ae10000000a1550b0/frameset.htm
<b>For Mapping Lookups~</b>
/people/alessandro.guarneri/blog/2006/03/27/sap-xi-lookup-api-the-killer
/people/sravya.talanki2/blog/2005/12/21/use-this-crazy-piece-for-any-rfc-mapping-lookups
This blog and article deals with calling your RFC from your JAVA MAPPING / User Defined Function.
https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/uuid/801376c6-0501-0010-af8c-cb69aa29941c
Java Mapping
http://help.sap.com/saphelp_nw04/helpdata/en/e2/e13fcd80fe47768df001a558ed10b6/content.htm
DOM parser API
http://java.sun.com/j2se/1.4.2/docs/api/org/w3c/dom/package-frame.html
On how to create XML docs with SAX and DOM go thruugh these links:
http://www.cafeconleche.org/books/xmljava/chapters/ch09.html
http://www.cafeconleche.org/books/xmljava/chapters/ch06.html
Also go through these Blogs....
/people/prasad.ulagappan2/blog/2005/06/08/sax-parser
/people/prasad.ulagappan2/blog/2005/06/29/java-mapping-part-i
/people/prasad.ulagappan2/blog/2005/06/29/java-mapping-part-ii
/people/prasad.ulagappan2/blog/2005/06/29/java-mapping-part-iii
/people/sravya.talanki2/blog/2005/12/21/use-this-crazy-piece-for-any-rfc-mapping-lookups
Thanks !! -
RFC lookup to return multiple parameters
Hi,
I have a File to Idoc scenario involving RFC lookups.
The RFC in this case has 2 input parameters and returns 5 output parameters in runtime. Can anybody help me with the UDF that can be used to send 2 parameters as input to the RFC and receive the 5 output parameters in the mapping and post it to the target Idoc structure.
Your help would be much appreciated !
Thanks & Regards,
Sherin Jose PHi,
Please find the below UDF that i used when i got the same requirement.
MySource structure is :
MT_Source
SSN
My Target Structure is :
ZIdoc
Empame
indClientSite
doj....etc
My mapping program is like this....
ssn---->findEmpInfo->findEmpName----EmpName
findClientSite---->clientsite
UDFCode:
public String findEmpInfo(String ssn, Container container) throws StreamTransformationException{
String inputString ="<?xml version=\"1.0\" encoding=\"UTF-8\"?> <ns0:RFC_GETEMPLOYEEDETAIL xmlns:ns0=\"urn:sap- com:document:sap:rfc:functions\"> <SSN>"ssn"</SSN> </ns0:RFC_GETEMPLOYEEDETAIL>"ssn"</SocialSecurityNo> </ns0:MT_EmpSSN>";
String targetValue = "";
AbstractTrace trace = container.getTrace();
RfcAccessor rAcc = null;
ByteArrayOutputStream out = null;
try{
Channel ch = LookupService.getChannel("BS_CLNT", "CC_Receiver_RFCLookup"); //DetermineChannel
rAcc = LookupService.getRfcAccessor(ch); //Get RfcAccessor
InputStream iStream = new ByteArrayInputStream(inputString.getBytes());
XmlPayload payload = LookupService.getXmlPayload(iStream); //get xml payload form of the input
Payload result = rAcc.call(payload); //make a lookup call
InputStream in = result.getContent();
byte[] bArray = new byte[512];
out = new ByteArrayOutputStream(512);
for(int i=in.read(bArray);i>0;i = in.read(bArray)){ out.write(bArray,0,i);
targetValue = out.toString();
catch(LookupException ex){
trace.addDebugMessage("LookupException"+ex.getMessage());
catch(IOException ex){
trace.addDebugMessage("IOException"+ex.getMessage());
finally{
if(out !=null){
try{
out.close();
catch(IOException ex){
trace.addDebugMessage("ErrorDuring Closing buffer"+ex.getMessage());
if(rAcc !=null){
try{ rAcc.close();
catch(LookupException ex){
trace.addDebugMessage("Error while closing RFCAccessor"+ex.getMessage());
GlobalContainer gContainer = container.getGlobalContainer();
gContainer.setParameter("RFCResponse",targetValue);
return targetValue;
public String findEmpName(String str, Container container) throws StreamTransformationException{
GlobalContainer gContainer = container.getGlobalContainer();
Object obj = gContainer.getParameter("RFCResponse");
String str ="";
str = obj.toString();
String st = "\"";
str = str.replaceAll("<", "<");
str = str.replaceAll(""", st);
str = str.replaceAll(">", ">");
String clntSite = "";
AbstractTrace trace = container.getTrace();
ByteArrayInputStream in;
in = new ByteArrayInputStream(str.getBytes());
try{
DocumentBuilderFactory dbFact = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuild = dbFact.newDocumentBuilder();
Document doc = dBuild.parse(in);
NodeList nList1 = doc.getElementsByTagName("CLNTSITE");
for(int i=0;i<nList1.getLength();i++){
Node nFname = nList1.item(0);
clntSite = nFname.getChildNodes().item(0).getNodeValue();
trace.addWarning("Client Site : "+nFname.getChildNodes().item(0).getNodeValue());
catch(Exception ex){
trace.addWarning("Exception Occurred :"+ex);
return clntSite;
Hop this will help you......
Thanks&Regards
Priyanka -
Hi all,
I am doing an RFC lookup to increment counter. I am facing a problem.
I followed the code written by Michael. https://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/a03e7b02-eea4-2910-089f-8214c6d1b439
My udf is as shown below: -
String content = "";
MappingTrace importanttrace;
importanttrace = container.getTrace();
java.util.Map param = container.getTransformationParameters();
String MSGID = (String) param.get (StreamTransformationConstants.MESSAGE_ID);
// filling the string with our RFC-XML (with values)
String m="<?xml version="1.0" encoding="UTF-8"?><ns0:_-GLB_-ZGT_RFBIBL00_COUNTER xmlns:ns0="urn:sap-com:document:sap:rfc:functions"><IM_V_FILENAME>CA10.NCH.FCIPAY04</IM_V_FILENAME><IM_V_MSGID>"MSGID"</IM_V_MSGID><IM_V_WRNO>DEVWR0001725</IM_V_WRNO></ns0:_-GLB_-ZGT_RFBIBL00_COUNTER>";
importanttrace.addWarning("Input value is "+m);
RfcAccessor accessor = null;
ByteArrayOutputStream out = null;
try
// 1. Determine a channel (Business system, Communication channel)
Channel channel = LookupService.getChannel(receiverBS,"CC_RFC_RCV_AMS_R3F_DEVWR001725");
// 2. Get a RFC accessor for a channel.
accessor = LookupService.getRfcAccessor(channel);
// 3. Create a xml input stream representing the function module request message.
InputStream inputStream = new ByteArrayInputStream(m.getBytes());
// 4. Create xml payload
XmlPayload payload = LookupService.getXmlPayload(inputStream);
// 5. Execute lookup.
Payload result = accessor.call(payload);
InputStream in = result.getContent();
out = new ByteArrayOutputStream(1024);
byte[] buffer = new byte[1024];
for (int read = in.read(buffer); read > 0; read = in.read(buffer)) {
out.write(buffer, 0, read);
content = out.toString();
catch(LookupException e)
importanttrace.addWarning("Error while lookup " + e.getMessage() );
catch(IOException e)
importanttrace.addWarning("Error " + e.getMessage() );
finally
if (out!=null) {
try {
out.close();
} catch (IOException e) {
importanttrace.addWarning("Error while closing stream " + e.getMessage() );
// 7. close the accessor in order to free resources.
if (accessor!=null) {
try {
accessor.close();
} catch (LookupException e) {
importanttrace.addWarning("Error while closing accessor " + e.getMessage() );
//returning the result u2013 RFC-XML.response
if ((content.substring(143,150)).equals("NOENTRY"))
ExceptionThrower.generate("INVALID INPUT DEVWR NUMBER OR ID" );
return "Nothing";
else
return (content.substring(143,155));
The problem i am facing is that, i am not able to pass the IM_V_MSGID parameter to the function module.
The other 2 parameters i can pass. that is IM_V_FILENAME and IM_V_WRNO.
i am able to extract the message ID using
java.util.Map param = container.getTransformationParameters();
String MSGID = (String) param.get (StreamTransformationConstants.MESSAGE_ID);
and displayed it in SXI_MONITOR trace also using importanttrace.addWarning("Input value is "+m);
i got the correct MSGID in the trace.But the problem is that this value is not getting passed to the FM. Cos the table is supposed to increment the counter whenever the MSGID value changes.
I tried hardcoding the MSGID value to 'abc' or '123' like values but the same thing happended. The counter will not increment. The FM is working perfectly when i run it and change the MSGID values manually.
Thanks
PratichiHi,
We have done this by creating an FM in XI ABAP stack:
FUNCTION Z_ZBXI_GET_PRE_MSG_ID.
""Local Interface:
*" IMPORTING
*" VALUE(I_CURRMSGID) TYPE CHAR40
*" EXPORTING
*" VALUE(E_PREMSGID) TYPE CHAR40
DATA: lv_currmsgid type SXMSPMAST-MSGGUID,
lv_parentmsgid LIKE SXMSPMAST-PARENTMSG,
lv_premsgid LIKE SXMSPMAST-MSGGUID.
lv_currmsgid = i_currmsgid.
select single PARENTMSG from SXMSPMAST into lv_parentmsgid where MSGGUID = lv_currmsgid.
e_premsgid = lv_parentmsgid.
ENDFUNCTION.
You need to call this FM through RFC lookup UDF in your mapping.
Let me know if it works for you.
Regards,
Shweta -
Hi,
I am trying to do RFC Lookup in XSLT.
I got this excellent mapping tool here at sdn:
RFC Lookup by Thorsten Nordholm Søbirk
But I am having problems when I uses this in a multi-record mapping. (many-to one) with lookup for every element.
Has anyone done IDOC with XSLT and RFC lookup (PI 7.11) ? Can you share the XSLT or experience?
Thx for sharingHi @ Fariah Ali
here is the mapping:
Inbound: IDOC HRMD_A07 (from ALE replication)
We only want to have Infotypes IT0001, IT0002, IT0050
Outbound:
<?xml version="1.0" encoding="utf-8"?>
<mt_I004_Time_Stammdaten>
<Datensatz>
<PersNr>PERSNR</PersNr>
<Name>ENAME</Name>
<Eintrittsdatum>BEGDA</Eintrittsdatum>
Austrittsdatum>ENDDA</Austrittsdatum>
<BeschArt/>
<Gueltigkeitsdatum/>
</Datensatz>
</mt_I004_Time_Stammdaten>
thx holger -
XSLT Mapping : RFC Lookup using java helper class
Hi All,
I am doing RFC Lookup in xslt mapping using java helper class. I have found blog for the same (http://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/05a3d62e-0a01-0010-14bc-adc8efd4ee14) However this blog is very advanced.
Can anybody help me with step by step approach for the same?
My basic questions are not answered in the blog as:
1) where to add the jar file of the java class used in xslt mapping.
I have added zip file of XSLT mapping in imported archived and using that in mapping.
Thanks in advace.
Regards,
RohanHi,
Can u please have look at this in detail , u can easily point out yourself the problem...
http://help.sap.com/saphelp_nw04/helpdata/en/55/7ef3003fc411d6b1f700508b5d5211/content.htm
Please observe the line,
xmlns:javamap="java:com.company.group.MappingClass
in XSLT mapping..
The packagename of class and class name and XSLT namespace should be matching...
Babu
Edited by: hlbabu123 on Sep 29, 2010 6:04 PM -
RFC Lookup API error in PI 7.1?
Hi Guys,
The RFC lookup which has been developed in PI 7.0 using the lookup API is unable to find the CC defined in the directory for a business system. after upgrading to PI 7.1. We are getting the error as below. This look up works perfectly fine in Dev(PI 7.1) and QA(PI 7.1) but in Prod(PI 7.1). We are on PI 7.1 EHP1 SP03.
Errorcom.sap.aii.mapping.lookup.LookupException: Plain exception:Error when calling an adapter by using the communication channel In_RFC_SAPLookUp (Party: , Service: Test, Object ID: 74e5e47336133351bebcb8c6a6bc68c8) The channel with object ID 74e5e47336133351bebcb8c6a6bc68c8 could not be found in the Integration Server Java Cache. Check if the channel exists in the Integration Builder Directory and execute a refresh of the Java Cach.
We did the cache refresh and also restarted the prod server but the error still persists. We have tried connecting to the prod receiver sap system from QA and the lookup works perfectly fine. We dont understand why it dosent work in prod.
any help or suggestions would be really appreciated.
Thanks,
SriniHi Rajesh,
The CC has the correct business system. We have also tried even by creating a new cc and it always says it cannot find the defined cc from the RFC lookup. We are passing this value as a constant value to the RFC lookup.
I could not understand why it is not finding only this CC? Is this something that RFC lookup is unable to find the CC?
any help would be appreciated
Thanks,
Srini -
RFC Lookup mapping error in PI 7.1
Hi Experts,
I´m getting mapping error when executing interface SOAP -> WS (SAP ECC) . The message mapping call RFC Lookup to SAP ECC.
When test the message mapping in Integration Builder the interface calls communication channel by RFC Lookup and works fine.
That interface was imported from QAS environment and was working fine, but in PRD it doesn´t works.
I checked the Interface Determination and the parameter is filled correctly with communication channel. The same communication channel was used on message mapping test.
The Interface Determination in SXI_CACHE has no value assigned to parameter in PRD environment, otherwise, the same interface determination in SXI_CACHE in QAS environment there is value (CC ID).
The problem persists after Cache Refresh in SXI_CACHE and CPA Cache.
Can anyone help me ?
Thanks in advance,
Regis Ferrato
Bellow the trace of error ocurred:Hi Regis,
Please check my reply in your other thread:
Re: RFC Lookup error cache in PI 7.1
Regards,
---Satish -
Exception Handling in RFC lookup
Hi Experts,
I have a query in RFC Lookup function working with PI 7.1, file to Idoc scenario.
I am using Enhance Receiver Determination to find the dynamic recivers.Here we have used a Functional Module which gives an output according to the the input parameter (which comes from input file). thus i have used RFC lookup to the remote system to fetch this info from FM.
Problem -
When the remote system is down or if the RFC lookup attemped & exceptions raised for some reason (RFC user authority has been changed & it was not able to perform the intended Job at remote system) , the message stuck in queue and block the several other messages from another interfaces which belongs to teh same queue.
Queries-
This is not allowed in production as it affects other services.
1>how can we handle the RFC lookup exception (in case of remote system is down or if the RFC lookup exception)
2>how can we perform Local lookup at PI box rather then remote lookup (the FM fetches the data from remote system)
3>Is Value mapping is relevant in this case raher the RFC lookup ? I am not sure as the values are dynamic & selected as per the FM's output.
Please provide your valuable insight .
Thanks in advance !
-JyotiHi Jyoti,
Answer for your 3 question.
1. RFC lookup will get execute on R/3 so if R/3 is down there no way that your RFC lookup will work as expected.
2. So if R/3 is down or RFC not able to get receiver system due to some problem.. then in that case.
On your Receiver determination at bottom
Configure u201Cif no receiver found proceed as followingu201D
In this you can have 3 option.
a. Error message u2013 if you select this the transaction will end with error message in SXMB_MONI
b. Ignore: if you select this execution will get ignored and there will not be any entry in SXMB_MONI
c. Select the following receiver. You can select this and can configured default receiver system in case if RFC not able to determine receiver then interface will get route to receiver system configured here.
3. As you mentioned values are dynamic then Value mapping doesnu2019t make any sense here. RFCl ookup is the right option and above are few other option in case you RFC lookup flailed.
Thanks,
Bhupesh -
Java RFC lookup from XSLT mapping
I tried to implement a generic Java RFC Lookup class to be called as a Java extension from my XSLT mapping. I found the How-To-Guide "Easy RFC lookup from XSLT mappings using a Java helper class" ([Easy RFC lookup pdf site|http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/05a3d62e-0a01-0010-14bc-adc8efd4ee14?quicklink=index&overridelayout=true]) and tailored the source code to my XSLT program. I am getting the error "Variable '$inputparam' has not been bound to a value". Can anyone tell me what I am missing? I am not familiar with java at all, and only moderately familiar with XSLT.
> I am getting the error "Variable '$inputparam' has not been bound to a value". Can anyone tell me what I am missing?
At runtime the variable does not get value. You need to assign value to the variable inputparam. Just curious why dont use the RFC lookup graphical which is very easy and no need to handle java programming. You need to configure just reciever RFC communication channel. -
PI 7.1 EHP1 RFC Lookup- Issue
Friends,
I'm seeing one strange issue in RFC Lookup behavior in my PI 7.1 EHP1 . Please give me some ideas for the same
Please see the below image for what I have done and what I'm seeing in the display queue.
http://www.flickr.com/photos/8764045@N06/4642237515/sizes/o/
To make it more simple - When I click on the Display queue on RFC lookup, I can see some 20 values with context changed. I removed my context and passed it to the UDF. When I check the input length in the UDF it's always giving 1, even though the display queue gives me 20 values.
Any ideas?
-Raj.Stefan/Sarvesh,
Thanks for your replies . Please see the below snapshots for complete picture.
UDF code & Properties -http://www.flickr.com/photos/8764045@N06/4643880555/sizes/o/
RFC Lookup Properties -http://www.flickr.com/photos/8764045@N06/4643880541/sizes/o/
Display Queues on UDF and RFC Lookup -http://www.flickr.com/photos/8764045@N06/4643883271/sizes/o/
I truly appreciate all your help on this.
-Raj.
Maybe you are looking for
-
Hi folks, We generally know that we write " SELECT Statements " in PBO. But if i write SELECT STATEMENT IN PAI. then wht will be the outcome and if there is any example plz suggest. thnking u. regards, satya.
-
So my iPad 2 that I just recently got has a very noticeable dent on the bottom of it going up(almost in half) in landscape mode. The dent won't let third party hard cases slide on it, and the screen is bleeding extra, and there is a white dot on the
-
Is there any way through which I can stop download of my ABAP programs???
Dear all, I want to know is there any way through which I can stop download of my ABAP programs so that no one can download or copy my programs without my permission. Thanks in Advance Sachin Gautam
-
Component Availability Check for Subcontracting PO
Hi, Is their any Setting to check the component availability and reservation of component material in stock after creating Subcontracting Purchase Order, As that is available in case of production order. Regards Siddharth
-
I can't not link my mac to my iPad or iPhone with iCloud.
I can't seem to have my mac linked via icloud to my ios devices. When I buy a song on my ipad, it will imediately show up on my iphone and vice versa. However, nothing shows up on my mac itunes. As well, if I buy a song through itunes on my mac, n