cancel
Showing results for 
Search instead for 
Did you mean: 

Calling RFC from a UDF

Former Member
0 Kudos

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

Accepted Solutions (1)

Accepted Solutions (1)

Shabarish_Nair
Active Contributor
0 Kudos
Shabarish_Nair
Active Contributor
0 Kudos

if you are on 7.1, things are much easier

7.1 Lookups - /people/jin.shin/blog/2008/02/15/sap-pi-71-mapping-enhancements-series-graphical-support-for-jdbc-and-rfc-lookups

Former Member
0 Kudos

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.

Shabarish_Nair
Active Contributor
0 Kudos

It will work on your current SP

The response of the Lookup will be your RFC response structure. You can parse the response for any particular field which you are interested in using a simple DOM parser (look into the same article for sample code).

former_member200962
Active Contributor
0 Kudos
Any ideas as from what SP of XI 3.0 does it work? (this is just for my knowledge thou ...)

if you mean the lookup functionality.......from SP 13

Regards,

Abhishek.

Former Member
0 Kudos

Hi,

I am trying it in the way...

https://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/a03e7b02-eea4-2910-089f-8214c6d1...

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.

Former Member
0 Kudos

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

Former Member
0 Kudos

If I understood correctly,

we have to create the MM between same RFC just to make sure we send in the correct xml format request to string variable m or a

correct me if im wrong.

Venkat.

Former Member
0 Kudos

Yes that is correct venkat. Take the source and target as the same RFC and do mm. Then map all the fields you are passing. If you are passing two fields then map those fields and send those two fields from source in the udf.

Regards,

---Satish

Former Member
0 Kudos

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

Former Member
0 Kudos

Venkat,

It complains you are missing quote " in the end. So please add that and give it a try.

Regards,

---Satish

Former Member
0 Kudos

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.

Former Member
0 Kudos

Venkat,

Can you put this and give a try:

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>";

Regards,

---Satish

Former Member
0 Kudos

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.

Former Member
0 Kudos

Venkat,

In this line of code:

Channel channel = LookupService.getChannel("BCS_800","rfc_channel");

Here you need to give your Busines system name and rfc communication channel name instead of BCS_800 and rfc_channel.

Regards,

---Satish

Former Member
0 Kudos

Satish/Santhosh,

I have copy pasted the CC and BS names from ID. So no chance of that error message.

They are currently used for many other interfaces so no prob with them

any clues?

thanks,

Venkat

Former Member
0 Kudos

paste your entire code,it looks like some payload variable declaration error

Did you define your payload as of type XmlPayload?

Rajesh

Former Member
0 Kudos

Venkat,

Can you put your code here so that I will try to solve your issue. I cannot see the urls because of some restrictions at my place.

Regards,

---Satish

Former Member
0 Kudos

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;
Former Member
0 Kudos

Venkat,

When you use this code and put a display code on this lookup, can you see in RWB --> communication channel for any error.

Regards,

---Satish

Former Member
0 Kudos

Venkat,

Did you add this in imports tab:

java.* and

com.sap.aii.mapping.lookup.*

Please tell what is the error you are getting.

Regards,

---Satish

Former Member
0 Kudos

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.

Former Member
0 Kudos

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;

Former Member
0 Kudos

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

Former Member
0 Kudos

Venkat,

Try to create a new rfc receiver comm. cahnnel and check out. Also please check whether they are not deleted (you never know). Also can you give me screen shot and send to my id which is in business card.

Regards,

---Satish

Former Member
0 Kudos

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.

Former Member
0 Kudos

Satish,

Addressing type was HTTP Destination for the previously used CC.

Now I have created new CC with logon details, it is working.

now Let me try with the actual RFC. Thanks for all your help.

Appreciate it.

Venkat.

Answers (1)

Answers (1)

Former Member
0 Kudos

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.