cancel
Showing results for 
Search instead for 
Did you mean: 

RFC Lookup

Former Member
0 Kudos

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

Accepted Solutions (0)

Answers (1)

Answers (1)

PriyankaAnagani
Active Contributor
0 Kudos

Hi,

Please go through the below discussion to return multiple values from RFC lookup.

Regards,

Priyanka

Former Member
0 Kudos

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

Former Member
0 Kudos

>>class' or 'interface' expected } ^

not sure but i guess u r using extra curly bracket somewhere in ur code.....remove the last curly bracket (after return) from ur code and then check??

PriyankaAnagani
Active Contributor
0 Kudos

Hi,

Might be in your code you have an extra } that closes the definition of a class..check it ..might be it is at testExecute() method....please verify it !

Regards,

Priyanka

Former Member
0 Kudos

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

baskar_gopalakrishnan2
Active Contributor
0 Kudos

str.replaceAll(string,string)

supports only two arguments or parameters. You send more..so you get error

example:

str.replaceAll(" ","");

PriyankaAnagani
Active Contributor
0 Kudos

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