on 11-30-2011 8:52 AM
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Priyanka
If I use your code on the first udf I get the following error.
Source code has syntax error: D:/usr/sap/XID/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Map47ec41d01b4311e1cf130023aefc99f4/source/com/sap/xi/tf/_MM_EmployeeMaster_2_.java:329: 'class' or 'interface' expected public static void main(String[] args) throws Exception{/!_$ClNRep_/_MM_EmployeeMaster_2_ st = new /!_$ClNRep_/_MM_EmployeeMaster_2_(); st.testExecute(); } ^ D:/usr/sap/XID/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Map47ec41d01b4311e1cf130023aefc99f4/source/com/sap/xi/tf/_MM_EmployeeMaster_2_.java:330: 'class' or 'interface' expected } ^ D:/usr/sap/XID/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Map47ec41d01b4311e1cf130023aefc99f4/source/com/sap/xi/tf/_MM_EmployeeMaster_2_.java:331: 'class' or 'interface' expected ^ 3 errors
Regards,
CJ
Hi Priyanka,
I fixed the first udf and it's working now, now on the 2 udf i get the following error.
Source code has syntax error: D:/usr/sap/XID/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Mapd9b9c1401b6211e1c5910023aefc99f4/source/com/sap/xi/tf/_MM_EmployeeMaster_2_.java:308: replaceAll(java.lang.String,java.lang.String) in java.lang.String cannot be applied to (java.lang.String,java.lang.String,java.lang.String,java.lang.String) str = str.replaceAll("<", "<","", st); ^ 1 error
Regards,
CJ
Hi,
As Bhaskar told, replaceAll method takes only two parameters. But you're passing four..because of that you're getting error. Please modify your statement such that it contains only two input parameters.
>>>str = str.replaceAll("<"<","", st);
It can be str = str.replaceAll("<"," ");
Regards,
Priyanka
User | Count |
---|---|
91 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.