cancel
Showing results for 
Search instead for 
Did you mean: 

RFC lookup to return multiple parameters

sherin_jose4
Participant
0 Kudos

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

Accepted Solutions (1)

Accepted Solutions (1)

PriyankaAnagani
Active Contributor
0 Kudos

Hi,

Previously i got the same requirement. What i did is....in one UDF i performed RFC lookup and parsed the result and saved the output values(5 in your case) in a container or global container and using different UDF's i accessed the required output and mapped it to the target. i.e lets say if i want to map 5 fields. I wrote 5 udfs. In 1st UDF i performed lookup & saved the result in container and in second UDF i retrieved second value from container and mapped to target , In 3rd Udf i retriedved 3rd value.... etc......Hope it will help you please try it once.

Thanks&Regards

Priyanka

Edited by: priyanka.anagani on Jun 20, 2011 2:38 PM

Former Member
0 Kudos

This solution is a way that i've follow too in an old project.

Just another advice: You can create only 1 UDF to GET values from global container, and in input parameter you can pass the variable name that you want to get (and perform the get function dinamically).

You can do something like this:

Function DBLOOKUP_GETDATA

Imports: java.lang.*;java.util.*;

public void DBLookUP_GetData(String[] FieldName,ResultList result,Container container){

//write your code here
result.addValue((String)hashMap.get(FieldName));

}

You can follow my blog post:

http://simonlesflex.wordpress.com/2010/12/07/pi-oracle-dblookup/

Marçal_Oliveras
Active Contributor
0 Kudos

If you don't like the Global Container, you can use a variable on the parent node of the target structure:

[http://help.sap.com/saphelp_nwpi71/helpdata/en/1d/1140dc082d4c009580100d7efc544a/frameset.htm]

sherin_jose4
Participant
0 Kudos

Priyanka,

Could you please share the code for RFC lookup and the UDF to call the global variables. It would be of much help for me.

Thanks & Regards,

Sherin Jose P

PriyankaAnagani
Active Contributor
0 Kudos

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

Former Member
0 Kudos

Take a look to my blog post, in the link above for an example of Lookup & Global Variables

Answers (1)

Answers (1)

sherin_jose4
Participant
0 Kudos

Thanks Priyanka, that was really helpful.

spantaleoni,

The link you have specified is for a DB lookup and i have asked doubt about RFC lookup. Anyways, thanks for the info.

Former Member
0 Kudos

Yes, you need to change only the comunication channel to call in the UDF from JDBC to RFC.