on 06-20-2011 1:07 PM
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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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/
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("<", "<");
str = str.replaceAll(""", st);
str = str.replaceAll(">", ">");
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
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
90 | |
10 | |
10 | |
10 | |
7 | |
7 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.