Hi Guys,
I need some help here, I am not a java fundi.
I found this code on RFC Lookup's and got it to work for me, but I need it to return all the data in a list for me and as it the code is currently it only returns one value.
CODE:
// declare parameters
String returnValue = "";
String rfcXML = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><ns0:ZEXI0970 xmlns:ns0=\"urn:sap-com:document:sap:rfc:functions\"><ZPRCTR_TAB><item><PRCTR><PRCTR/></item></ZPRCTR_TAB></ns0:ZEXI0970>";
AbstractTrace trace = container.getTrace();
RfcAccessor accessor = null;
ByteArrayOutputStream out = null;
try
{
// 1. Determine a communication channel (Business system + Communication channel)
Channel channel = LookupService.getChannel(BusinessSystem,CommChannel);
// 2. Get a RFC accessor for the channel.
accessor = LookupService.getRfcAccessor(channel);
// 3. Create an XML input stream that represents the RFC request message.
InputStream inputStream = new ByteArrayInputStream(rfcXML.getBytes());
// 4. Create the XML Payload
XmlPayload payload = LookupService.getXmlPayload(inputStream);
// 5. Execute the lookup.
Payload result = null;
result = accessor.call(payload);
InputStream in = result.getContent();
// 6. Create a DOM structure from the input XML
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document document = builder.parse(in);
NodeList list = document.getElementsByTagName("PRCTR"); // The lookupValue is available as PRCTR tag in the response
Node node = list.item(0);
//trace.addDebugMessage("TEST" + list.item(0).toString());
if (node != null) {
node = node.getFirstChild();
if (node != null) {
returnValue = node.getNodeValue();
}
}
// 7. To free resources, close the accessor..
if (accessor!=null) {
try {
accessor.close();
} catch (LookupException e) {
trace.addWarning("Error while closing accessor " + e.getMessage() );
}
}
} catch (Exception e) {
trace.addWarning("Error" + e);
}
// 8. return a single id value to the message mapping
return returnValue;
Help in this regard would be very much appreciated.
Kind Regards,
CJ Bester