Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

RFC lookup to return multiple parameters

Hi,

I have a File to Idoc scenario involving RFC lookups.

The RFC in this case has 2 input parameters and returns 5 output parameters in runtime. Can anybody help me with the UDF that can be used to send 2 parameters as input to the RFC and receive the 5 output parameters in the mapping and post it to the target Idoc structure.

Your help would be much appreciated !

Thanks & Regards,

Sherin Jose P

Former Member
replied

Hi,

Please find the below UDF that i used when i got the same requirement.

MySource structure is :

MT_Source

SSN

My Target Structure is :

ZIdoc

Empame

indClientSite

doj....etc

My mapping program is like this....

ssn---->findEmpInfo->findEmpName----EmpName

findClientSite---->clientsite

UDFCode:

public String findEmpInfo(String ssn, Container container) throws StreamTransformationException{

String inputString ="<?xml version=\"1.0\" encoding=\"UTF-8\"?> <ns0:RFC_GETEMPLOYEEDETAIL xmlns:ns0=\"urn:sap- com:document:sap:rfc:functions\"> <SSN>"ssn"</SSN> </ns0:RFC_GETEMPLOYEEDETAIL>"ssn"</SocialSecurityNo> </ns0:MT_EmpSSN>";

String targetValue = "";

AbstractTrace trace = container.getTrace();

RfcAccessor rAcc = null;

ByteArrayOutputStream out = null;

try{

Channel ch = LookupService.getChannel("BS_CLNT", "CC_Receiver_RFCLookup"); //DetermineChannel

rAcc = LookupService.getRfcAccessor(ch); //Get RfcAccessor

InputStream iStream = new ByteArrayInputStream(inputString.getBytes());

XmlPayload payload = LookupService.getXmlPayload(iStream); //get xml payload form of the input

Payload result = rAcc.call(payload); //make a lookup call

InputStream in = result.getContent();

byte[] bArray = new byte[512];

out = new ByteArrayOutputStream(512);

for(int i=in.read(bArray);i>0;i = in.read(bArray)){ out.write(bArray,0,i);

}

targetValue = out.toString();

}

catch(LookupException ex){

trace.addDebugMessage("LookupException"+ex.getMessage());

}

catch(IOException ex){

trace.addDebugMessage("IOException"+ex.getMessage());

}

finally{

if(out !=null){

try{

out.close();

}

catch(IOException ex){

trace.addDebugMessage("ErrorDuring Closing buffer"+ex.getMessage());

}

}

if(rAcc !=null){

try{ rAcc.close();

}

catch(LookupException ex){

trace.addDebugMessage("Error while closing RFCAccessor"+ex.getMessage());

}

}

}

GlobalContainer gContainer = container.getGlobalContainer();

gContainer.setParameter("RFCResponse",targetValue);

return targetValue;

}

public String findEmpName(String str, Container container) throws StreamTransformationException{

GlobalContainer gContainer = container.getGlobalContainer();

Object obj = gContainer.getParameter("RFCResponse");

String str ="";

str = obj.toString();

String st = "\"";

str = str.replaceAll("&lt;", "<");

str = str.replaceAll("&quot;", st);

str = str.replaceAll("&gt;", ">");

String clntSite = "";

AbstractTrace trace = container.getTrace();

ByteArrayInputStream in;

in = new ByteArrayInputStream(str.getBytes());

try{

DocumentBuilderFactory dbFact = DocumentBuilderFactory.newInstance();

DocumentBuilder dBuild = dbFact.newDocumentBuilder();

Document doc = dBuild.parse(in);

NodeList nList1 = doc.getElementsByTagName("CLNTSITE");

for(int i=0;i<nList1.getLength();i++){

Node nFname = nList1.item(0);

clntSite = nFname.getChildNodes().item(0).getNodeValue();

trace.addWarning("Client Site : "+nFname.getChildNodes().item(0).getNodeValue());

}

}

catch(Exception ex){

trace.addWarning("Exception Occurred :"+ex);

}

return clntSite;

}

Hop this will help you......

Thanks&Regards

Priyanka

0 View this answer in context

Helpful Answer

by
Not what you were looking for? View more on this topic or Ask a question