on 11-30-2007 8:16 AM
My UDF Source code has an syntax error: missing return statement }
but i can´t find the error.
any ideas ?
//write your code here
String content = "";
MappingTrace importanttrace;
importanttrace = container.getTrace();
// filling the string with our RFC-XML (with values)
String m ="<?xml version="1.0" encoding="UTF-8"?><ns0:Z_GET_PRODH xmlns:ns0="urn:sap-com:document:sap:rfc:functions"><IN_MATNR>2100018693</IN_MATNR></ns0:Z_GET_PRODH>";
RfcAccessor accessor = null;
ByteArrayOutputStream out = null;
try
{
// 1. Determine a channel (Business system, Communication channel)
Channel channel = LookupService.getChannel("xxxxxxxxxx","yyyyyyyy");
// 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() );
}
}
}
Message was edited by:
Gordon Breuer
Gordon,
Guess you are using the code shown in Michal's article as it is. You need to parse the XML string and get the desired value you need and use return statement (if simple UDF) or resultlist.addvalue (if advanced UDF) to pass the output.
Regards,
Jai Shankar
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You need to parse the XML first. The RFC response that is received now is in a XML format. You can either use a SAX/DOM parser and parse the XML to get the value you need and then finally you have to use return statement to pass the result of the UDF.
P.S: This return is different from the RFC response return value.
Sample code to parse the XL using DOM parser
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
documentInput = builder.parse(bais);
NodeList list = documentInput.getElementsByTagName("RESULT"); //Getting all RESULT tags in the node list
Node node = list.item(0); //Assuming only 1 RESULT is there in my RFC response
String strOutput = node.getFirstChild().getNodeValue(); //Get the value of the RESULT tag.
Regards,
Jai Shankar
I have a solution without DOM parser. The XML code is seen as a sting and the code looks for a specific tag. In my case it is OUTPUT, you can adjust the code to your tag.
String content = "";
MappingTrace importanttrace;
importanttrace = container.getTrace();
// filling the string with our RFC-XML (with values)
String m = "<rfc:ZZSG_TEST_XSLT_LOOKUP xmlns:rfc="urn:sap-com:document:sap:rfc:functions">"
+ "<INPUT>" + request + "</INPUT></rfc:ZZSG_TEST_XSLT_LOOKUP>";
RfcAccessor accessor = null;
ByteArrayOutputStream out = null;
try
{
// 1. Determine a channel (Business system, Communication channel)
Channel channel = LookupService.getChannel("Airline_Group_Two","RFC");
// 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 RFC-XML.response
int start = content.indexOf("<OUTPUT>") + 8;
int end = content.indexOf("</OUTPUT>");
if (end > start && start > 8)
content = content.substring(start,end);
return content;
User | Count |
---|---|
80 | |
24 | |
11 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.