Skip to Content
0
Former Member
Jan 07, 2008 at 07:10 AM

RFC Lookup API

76 Views

Hi Everybody,

when using the RFC lookUp API in UDF I am geting a whole XML Document as the response.

What is the easiest way to Check the Value Exist or Not.

Passing a Value From Source .

Below Blog will Display whole XML Document as the response

(https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/a03e7b02-eea4-2910-089f-8214c6d1b439)

I am getting a Below message in my Target system.

<?xml version = "1.0" encoding="UTF-8"?

Here is MY COde of UDF .

String content = " ";

MappingTrace importanttrace;

importanttrace = container.getTrace () ;

String m = "<?xml version = " 1.0 " encoding= "UTF-8 "?><PO:BAPI_PO_GETDETAIL xmlns:PO= "urn:sap-com:document:sap:rfc:functions "><PURCHASEORDER>4568798300</PURCHASEORDER></PO:BAPI_PO_GETDETAIL>" ;

RfcAccessor accessor = null;

ByteArrayOutputStream out = null;

try

{

// 1. Determine a channel (Business system, Communication channel)

Channel channel = LookupService.getChannel("UTF10001","Samplelookup");

// 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

return content;

I am trying to check the po exist in R/3 or not.