on 07-20-2009 4:13 AM
I would like to call RFC with 4 parameters.
1. To
2. From
3. Content
4. CC
I had already looked at this solution and for some reason this doesnt seem to work.
/people/bhavesh.kantilal/blog/2006/07/25/triggering-xi-alerts-from-a-user-defined-function
My exact requirement is :
I have to send a email if a field value in the response message is 1.
Has anyone tried calling a RFC from UDF? Can someone please provide me with the code for UDF?
thanks,
Venkat.
Edited by: Venkat A on Jul 19, 2009 11:18 PM
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I have not started on it yet.
Quick question... do you think this works good for the response message?
I am on 7.0 SP 14. I think I have to switch over to the UDF.
Any ideas as from what SP of XI 3.0 does it work? (this is just for my knowledge thou ...)
Thanks Shabarish and indirectly Michal too
will keep you updated... meanwhile any more valuable suggestion ... always welcome
Venkat.
Hi,
I am trying it in the way...
I have imported BAPI, I have mapped them, then I have created new scenario.
I have created the UDF as per this in my curent scenario mapping.
I am stuck at a point and confused as where do I need to map between the RFC mapping and my actual scenario mapping
Can someone throw more light on it?
thanks,
Venkat.
Venkat,
If you see the code in the udf it has:
String m = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><p2:BAPI_PO_GETDETAIL xmlns:p2=\"urn:sap-com:document:sap:rfc:functions\"><PURCHASEORDER>4500014790</PURCHASEORDER></p2:BAPI_PO_GETDETAIL>";
Here he is sending a constant 4500014790 as purchase order number. Infact in your mapping this would be the source value you are sending. So in udf take one argument say 'a' then pass the value here.
But before that you map all the fields in a differnt mapping for RFC for getting the payload like above, else you have to key in manually.
Regards,
---Satish
Source code has syntax error:
G:/usr/sap/XID/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Map962962a0764111de835200188be5e894/source/com/sap/xi/tf/_FileToFile_.java:63: ';' expected String m = "<?xml version="1.0" encoding="UTF-8"?><ns0:BAPI_PO_GETDETAIL xmlns:ns0="urn:sap-com:document:sap:rfc:functions"><PURCHASEORDER>4500015429</PURCHASEORDER></ns0:BAPI_PO_GETDETAIL>; ^
G:/usr/sap/XID/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Map962962a0764111de835200188be5e894/source/com/sap/xi/tf/_FileToFile_.java:63: unclosed string literal String m = "<?xml version="1.0" encoding="UTF-8"?><ns0:BAPI_PO_GETDETAIL xmlns:ns0="urn:sap-com:document:sap:rfc:functions"><PURCHASEORDER>4500015429</PURCHASEORDER></ns0:BAPI_PO_GETDETAIL>;
I checked ";" it is existing for all lines.
I am not sure why it is throwing me unclosed string literal
Thanks Satish.
Now a different error...
Source code has syntax error: G:/usr/sap/XID/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Map0c1b3690764311debcf900188be5e894/source/com/sap/xi/tf/_FileToFile_.java:63: ';' expected String m = "<?xml version="1.0" encoding="UTF-8"?><ns0:BAPI_PO_GETDETAIL xmlns:ns0="urn:sap-com:document:sap:rfc:functions"><PURCHASEORDER>4500015429</PURCHASEORDER></ns0:BAPI_PO_GETDETAIL>"; ^ 1 error
Venkat.
Hi Satish,
Source code has syntax error: G:/usr/sap/XID/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Map3fd670a0764611dea42700188be5e894/source/com/sap/xi/tf/_FileToFile_.java:79: cannot resolve symbol symbol : variable payload location: class com.sap.xi.tf._FileToFile_ payload = LookupService.getXmlPayload(inputStream); ^
G:/usr/sap/XID/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Map3fd670a0764611dea42700188be5e894/source/com/sap/xi/tf/_FileToFile_.java:82: cannot resolve symbol symbol : variable payload location: class com.sap.xi.tf._FileToFile_ Payload result = accessor.call(payload);
^ 2 errors
Thanks,
Venkat.
String content = "";
MappingTrace importanttrace;
importanttrace = container.getTrace();
// filling the string with our RFC-XML (with values)
String m = "<?xml version="1.0" encoding="UTF-8"?><ns0:BAPI_PO_GETDETAIL xmlns:ns0="urn:sap-com:document:sap:rfc:functions"><PURCHASEORDER>4500015429</PURCHASEORDER></ns0:BAPI_PO_GETDETAIL>";
RfcAccessor accessor = null;
ByteArrayOutputStream out = null;
try
{
// 1. Determine a channel (Business system, Communication channel)
Channel channel = LookupService.getChannel("SAP_ERP_008","RFC_RCV_ERP");
// 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 u2013 RFC-XML.response
return content;
error:
Source code has syntax error: G:/usr/sap/XID/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Mape9b4ccc076d711dec8d600188be5e894/source/com/sap/xi/tf/_FileToFile_.java:63: ';' expected String m = "<?xml version="1.0" encoding="UTF-8"?><ns0:BAPI_PO_GETDETAIL xmlns:ns0="urn:sap-com:document:sap:rfc:functions"><PURCHASEORDER>4500015429</PURCHASEORDER></ns0:BAPI_PO_GETDETAIL>"; ^ 1 error
in imports i have placed
java.io.*;com.sap.aii.mapping.lookup.*;
Thanks,
Venkat.
Venkat,
Put this code and see what ever you are getting. Copy as it is and let me know the errors. It is working for me.
String content = "";
MappingTrace importanttrace;
importanttrace = container.getTrace();
// filling the string with our RFC-XML (with values)
String m = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><p2:BAPI_PO_GETDETAIL xmlns:p2=\"urn:sap-com:document:sap:rfc:functions\"><PURCHASEORDER>4500015429</PURCHASEORDER></p2:BAPI_PO_GETDETAIL>";
RfcAccessor accessor = null;
ByteArrayOutputStream out = null;
try
{
// 1. Determine a channel (Business system, Communication channel)
Channel channel = LookupService.getChannel("SAP_ERP_008","RFC_RCV_ERP");
// 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 u2013 RFC-XML.response
return content;
now it says successful but says cannot find the CC and BS.
I copied and pasted the CC and BS from ID ... and there are many scenarios working using these
Compilation of FileToFile successful
u2022 Error while lookup Plain exception:Problem when calling an adapter by using communication channel RFC_RCV_ERP (Party: , Service: SAP_ERP_008, Object ID: 5cc803bc6166380795d993a8b00c0983) Check whether the communication channel exists in the Integration Directory; also check the cache notifications for the instance Integration Server (central Adapter-Engine) Channel object with Id Channel:5cc803bc6166380795d993a8b00c0983 not available in CPA Cache.
com.sap.aii.mapping.lookup.LookupException: Problem when calling an adapter by using communication channel RFC_RCV_ERP (Party: , Service: SAP_ERP_008, Object ID: 5cc803bc6166380795d993a8b00c0983) Check whether the communication channel exists in the Integration Directory; also check the cache notifications for the instance Integration Server (central Adapter-Engine) Channel object with Id Channel:5cc803bc6166380795d993a8b00c0983 not available in CPA Cache.
at com.sap.aii.ibrun.server.lookup.AdapterProxyLocal.<init>(AdapterProxyLocal.java:61)
at com.sap.aii.ibrun.server.lookup.SystemAccessorInternal.getProxy(SystemAccessorInternal.java:98)
at com.sap.aii.ibrun.server.lookup.SystemAccessorInternal.<init>(SystemAccessorInternal.java:38)
at com.sap.aii.ibrun.server.lookup.SystemAccessorHmiServer.getConnection(SystemAccessorHmiServer.java:270)
at com.sap.aii.ibrun.server.lookup.SystemAccessorHmiServer.process(SystemAccessorHmiServer.java:70)
at com.sap.aii.utilxi.hmis.server.HmisServiceImpl.invokeMethod(HmisServiceImpl.java:169)
at com.sap.aii.utilxi.hmis.server.HmisServer.process(HmisServer.java:178)
at com.sap.aii.utilxi.hmis.web.HmisServletImpl.processRequestByHmiServer(HmisServletImpl.java:297)
at com.sap.aii.utilxi.hmis.web.HmisServletImpl.processRequestByHmiServer(HmisServletImpl.java:212)
at com.sap.aii.utilxi.hmis.web.workers.HmisInternalClient.doWork(HmisInternalClient.java:70)
at com.sap.aii.utilxi.hmis.web.HmisServletImpl.doWork(HmisServletImpl.java:507)
at com.sap.aii.utilxi.hmis.web.HmisServletImpl.doPost(HmisServletImpl.java:655)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at com.sap.engine.services.servlets_jsp.server.HttpHandlerImpl.runServlet(HttpHandlerImpl.java:401)
at com.sap.engine.services.servlets_jsp.server.HttpHandlerImpl.handleRequest(HttpHandlerImpl.java:266)
at com.sap.engine.services.httpserver.server.RequestAnalizer.startServlet(RequestAnalizer.java:387)
at com.sap.engine.services.httpserver.server.RequestAnalizer.startServlet(RequestAnalizer.java:365)
at com.sap.engine.services.httpserver.server.RequestAnalizer.invokeWebContainer(RequestAnalizer.java:944)
at com.sap.engine.services.httpserver.server.RequestAnalizer.handle(RequestAnalizer.java:266)
at com.sap.engine.services.httpserver.server.Client.handle(Client.java:95)
at com.sap.engine.services.httpserver.server.Processor.request(Processor.java:175)
at com.sap.engine.core.service630.context.cluster.session.ApplicationSessionMessageListener.process(ApplicationSessionMessageListener.java:33)
at com.sap.engine.core.cluster.impl6.session.MessageRunner.run(MessageRunner.java:41)
at com.sap.engine.core.thread.impl3.ActionObject.run(ActionObject.java:37)
at java.security.AccessController.doPrivileged(Native Method)
at com.sap.engine.core.thread.impl3.SingleThread.execute(SingleThread.java:100)
at com.sap.engine.core.thread.impl3.SingleThread.run(SingleThread.java:170)
u2022 Error while lookup Plain exception:Problem when calling an adapter by using communication channel RFC_RCV_ERP (Party: , Service: SAP_ERP_008, Object ID: 5cc803bc6166380795d993a8b00c0983) Check whether the communication channel exists in the Integration Directory; also check the cache notifications for the instance Integration Server (central Adapter-Engine) Channel object with Id Channel:5cc803bc6166380795d993a8b00c0983 not available in CPA Cache.
com.sap.aii.mapping.lookup.LookupException: Problem when calling an adapter by using communication channel RFC_RCV_ERP (Party: , Service: SAP_ERP_008, Object ID: 5cc803bc6166380795d993a8b00c0983) Check whether the communication channel exists in the Integration Directory; also check the cache notifications for the instance Integration Server (central Adapter-Engine) Channel object with Id Channel:5cc803bc6166380795d993a8b00c0983 not available in CPA Cache.
at com.sap.aii.ibrun.server.lookup.AdapterProxyLocal.<init>(AdapterProxyLocal.java:61)
at com.sap.aii.ibrun.server.lookup.SystemAccessorInternal.getProxy(SystemAccessorInternal.java:98)
at com.sap.aii.ibrun.server.lookup.SystemAccessorInternal.<init>(SystemAccessorInternal.java:38)
at com.sap.aii.ibrun.server.lookup.SystemAccessorHmiServer.getConnection(SystemAccessorHmiServer.java:270)
at com.sap.aii.ibrun.server.lookup.SystemAccessorHmiServer.process(SystemAccessorHmiServer.java:70)
at com.sap.aii.utilxi.hmis.server.HmisServiceImpl.invokeMethod(HmisServiceImpl.java:169)
at com.sap.aii.utilxi.hmis.server.HmisServer.process(HmisServer.java:178)
at com.sap.aii.utilxi.hmis.web.HmisServletImpl.processRequestByHmiServer(HmisServletImpl.java:297)
at com.sap.aii.utilxi.hmis.web.HmisServletImpl.processRequestByHmiServer(HmisServletImpl.java:212)
at com.sap.aii.utilxi.hmis.web.workers.HmisInternalClient.doWork(HmisInternalClient.java:70)
at com.sap.aii.utilxi.hmis.web.HmisServletImpl.doWork(HmisServletImpl.java:507)
at com.sap.aii.utilxi.hmis.web.HmisServletImpl.doPost(HmisServletImpl.java:655)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at com.sap.engine.services.servlets_jsp.server.HttpHandlerImpl.runServlet(HttpHandlerImpl.java:401)
at com.sap.engine.services.servlets_jsp.server.HttpHandlerImpl.handleRequest(HttpHandlerImpl.java:266)
at com.sap.engine.services.httpserver.server.RequestAnalizer.startServlet(RequestAnalizer.java:387)
at com.sap.engine.services.httpserver.server.RequestAnalizer.startServlet(RequestAnalizer.java:365)
at com.sap.engine.services.httpserver.server.RequestAnalizer.invokeWebContainer(RequestAnalizer.java:944)
at com.sap.engine.services.httpserver.server.RequestAnalizer.handle(RequestAnalizer.java:266)
at com.sap.engine.services.httpserver.server.Client.handle(Client.java:95)
at com.sap.engine.services.httpserver.server.Processor.request(Processor.java:175)
at com.sap.engine.core.service630.context.cluster.session.ApplicationSessionMessageListener.process(ApplicationSessionMessageListener.java:33)
at com.sap.engine.core.cluster.impl6.session.MessageRunner.run(MessageRunner.java:41)
at com.sap.engine.core.thread.impl3.ActionObject.run(ActionObject.java:37)
at java.security.AccessController.doPrivileged(Native Method)
at com.sap.engine.core.thread.impl3.SingleThread.execute(SingleThread.java:100)
at com.sap.engine.core.thread.impl3.SingleThread.run(SingleThread.java:170)
Executed successfully
Edited by: Venkat A on Jul 22, 2009 1:38 PM
Hi Satish,
I suspect the change we made for the RFC-XML.
Please have a look at what Shiv prasad Dixit discussed here.
Could it be a reason that the RFC-XML that we are sending in XML format has issues?
However, to isolate I send the XML again by removing \ but we get the same error as earlier..
so Please help.
thanks
Venkat.
Venkat ,
Usually this type of error comes when you don't pass the variables properly :
Like Business System name and RFCchannel ...!!!
P.S: A simple way to create the RFC request string will be put the RFC request structure in a message mapping. Go to the Test tab and enter the value you want for the Iinput fields.Now click on the "src" button to see the source code of this xml. You can use this as your RFC request string.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
87 | |
10 | |
10 | |
10 | |
7 | |
6 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.