cancel
Showing results for 
Search instead for 
Did you mean: 

need help on RFC look up in PI 7.0

Former Member
0 Kudos

Dear experts ,

I am working on Jdbc to Abap Proxy  scenario where i need to perform a RFC Look up . I have searched in SCN  and found some help ful blogs, but still need more information in below points.

My requirement is need to fetch Cost Center (KOSTL) by taking Personal number(PERNR)  as Input parameter.

1) Do we have to create and import the RFC into PI ?

2) Do we need to create a UDF ? If yes, Kindly provide some useful links.

Thanks in Advance,

Mohammed

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Hello,

1) No, it's not mandatory to import RFC, but it's advisable to do it. So that when u are generating ur RFC request in UDF u can refer the (imported) RFC XML structure.

2) Yes, u have to write UDF becoz in PI7.0 there is no inbuilt function for RFC lookup

Thanks

Amit Srivastava

Former Member
0 Kudos

Thank you Amit & Hareesh,

sorry for the late response. i had written UDF, but from do i need to import the jar files.

i had gone through the threads in SCN, it is given that we need to create a package & class then we need to need to import in XI through imported Archive. i didn't understand this.

can you please explain.

thanks in advance.

Former Member
0 Kudos

Hello,

Yes, u have to zip ur class file and import the same in PI.

Follow below steps:

1) Right click on ur project -> export -> Select Archive File (under General) and save the same on ur machine as zip file

2) once done, open ur saved zip file and then extract ur project.

3) Open ur extracted folder and search for "bin" folder inside it.

4) Under that u will find a "com" folder, so just zip the same and import it under PI as Imported Archive

Thanks

Amit Srivastava

former_member184720
Active Contributor
0 Kudos

Hi Feroz - In case you are going with the UDF, you can directly import the necessary jar files under imported archive i believe.

Refer to the below thread on how to give import statements in your UDF..

Former Member
0 Kudos

Hello,

I had replied above thinking that u want to import JM in PI - overlooked UDF part completely. So, Hareesh's pointer would be more helpful in case u want to add external packages in ur UDF.

BTW, i was just wondering why do u want to import class file in RFC lookup UDF?

Thanks

Amit Srivastava

Former Member
0 Kudos

Hi

You don't need any jar files to write the UDF for RFC look up.

Sample Code:

java.util.Map map;

try {

String msgid;

map = container.getTransformationParameters();

msgid = (String) map.get(StreamTransformationConstants.MESSAGE_ID);

Channel channel = LookupService.getChannel("DE1CLNTXXX","CC_RFC_R_PI");

RfcAccessor accessor = LookupService.getRfcAccessor(channel);

String rfcXML= "<ns0:SALERT_CREATE xmlns:ns0=\"urn:sap-com:document:sap:rfc:functions\">"+

      "<IP_ALIAS/>"+

      "<IP_APPLICATION_GUID/>"+

      "<IP_CAT>ALERT_TEST_UDF</IP_CAT>"+

      "<IP_XML_CONTAINER/>"+

      "<IT_CONTAINER>"+

         "<item>"+

            "<ELEMENT>ZCUSTOMER</ELEMENT>"+

            "<TAB_INDEX>0</TAB_INDEX>"+

            "<ELEMLENGTH>20</ELEMLENGTH>"+

            "<TYPE>C</TYPE>"+

            "<VALUE>"+pnum+"</VALUE>"+

         "</item>"+

           "<item>"+

            "<ELEMENT>ZMSGID</ELEMENT>"+

            "<TAB_INDEX>1</TAB_INDEX>"+

            "<ELEMLENGTH>70</ELEMLENGTH>"+

            "<TYPE>C</TYPE>"+

            "<VALUE>"+msgid+"</VALUE>"+

         "</item>"+

      "</IT_CONTAINER>"+

    "</ns0:SALERT_CREATE>";

InputStream inputStream =new ByteArrayInputStream(rfcXML.getBytes());

XmlPayload payload = LookupService.getXmlPayload(inputStream);

Payload rfcOutPayload = accessor.call(payload);

throw new  StreamTransformationException ( " Message Mapping Failed because of invalid Customer number");

}

catch(Exception e)

{

  throw new RuntimeException("Exception while checking for Distribution channel : "+e);

}

Note : Before you write the UDF, the receiver RFC communication channel needs to be created in PI and function module should be created in ECC.

Former Member
0 Kudos

Hi indrajit,

  i had written :  java.util.Map map;" in the import secion of UDF. but still i am getting the following errors

******************************************************************************************************************

Source code has syntax error:  /usr/sap/XD1/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Map2d519647b0c211e39616000000844522/source/com/sap/xi/tf/_MM_RMF_TO_SAP_.java:3: cannot resolve symbol symbol : class map location: interface java.util.Map import com.sap.aii.mappingtool.tf3.*;import com.sap.aii.mappingtool.tf3.rt.*;import java.util.*;import java.io.*; import java.lang.reflect.*;import java.util.Map.map; ^ /usr/sap/XD1/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Map2d519647b0c211e39616000000844522/source/com/sap/xi/tf/_MM_RMF_TO_SAP_.java:257: cannot resolve symbol symbol : class RfcAccessor location: class com.sap.xi.tf._MM_RMF_TO_SAP_ RfcAccessor accessor = null; ^ /usr/sap/XD1/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Map2d519647b0c211e39616000000844522/source/com/sap/xi/tf/_MM_RMF_TO_SAP_.java:262: cannot resolve symbol symbol : class Channel location: class com.sap.xi.tf._MM_RMF_TO_SAP_ Channel channel = LookupService.getChannel(BS_SAP_R3,CC_RFC_LOOK_UP_CRMNEXT); ^ /usr/sap/XD1/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Map2d519647b0c211e39616000000844522/source/com/sap/xi/tf/_MM_RMF_TO_SAP_.java:262: cannot resolve symbol symbol : variable BS_SAP_R3 location: class com.sap.xi.tf._MM_RMF_TO_SAP_ Channel channel = LookupService.getChannel(BS_SAP_R3,CC_RFC_LOOK_UP_CRMNEXT); ^ /usr/sap/XD1/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Map2d519647b0c211e39616000000844522/source/com/sap/xi/tf/_MM_RMF_TO_SAP_.java:262: cannot resolve symbol symbol : variable CC_RFC_LOOK_UP_CRMNEXT location: class com.sap.xi.tf._MM_RMF_TO_SAP_ Channel channel = LookupService.getChannel(BS_SAP_R3,CC_RFC_LOOK_UP_CRMNEXT); ^ /usr/sap/XD1/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Map2d519647b0c211e39616000000844522/source/com/sap/xi/tf/_MM_RMF_TO_SAP_.java:262: cannot resolve symbol symbol : variable LookupService location: class com.sap.xi.tf._MM_RMF_TO_SAP_ Channel channel = LookupService.getChannel(BS_SAP_R3,CC_RFC_LOOK_UP_CRMNEXT); ^ /usr/sap/XD1/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Map2d519647b0c211e39616000000844522/source/com/sap/xi/tf/_MM_RMF_TO_SAP_.java:264: cannot resolve symbol symbol : variable LookupService location: class com.sap.xi.tf._MM_RMF_TO_SAP_ accessor = LookupService.getRfcAccessor(channel); ^ /usr/sap/XD1/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Map2d519647b0c211e39616000000844522/source/com/sap/xi/tf/_MM_RMF_TO_SAP_.java:268: cannot resolve symbol symbol : class XmlPayload location: class com.sap.xi.tf._MM_RMF_TO_SAP_ XmlPayload payload = LookupService.getXmlPayload(inputStream); ^ /usr/sap/XD1/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Map2d519647b0c211e39616000000844522/source/com/sap/xi/tf/_MM_RMF_TO_SAP_.java:268: cannot resolve symbol symbol : variable LookupService location: class com.sap.xi.tf._MM_RMF_TO_SAP_ XmlPayload payload = LookupService.getXmlPayload(inputStream); ^ /usr/sap/XD1/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Map2d519647b0c211e39616000000844522/source/com/sap/xi/tf/_MM_RMF_TO_SAP_.java:270: cannot resolve symbol symbol : class Payload location: class com.sap.xi.tf._MM_RMF_TO_SAP_ Payload result = null; ^ /usr/sap/XD1/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Map2d519647b0c211e39616000000844522/source/com/sap/xi/tf/_MM_RMF_TO_SAP_.java:275: cannot resolve symbol symbol : class DocumentBuilderFactory location: class com.sap.xi.tf._MM_RMF_TO_SAP_ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); ^ /usr/sap/XD1/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Map2d519647b0c211e39616000000844522/source/com/sap/xi/tf/_MM_RMF_TO_SAP_.java:275: cannot resolve symbol symbol : variable DocumentBuilderFactory location: class com.sap.xi.tf._MM_RMF_TO_SAP_ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); ^ /usr/sap/XD1/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Map2d519647b0c211e39616000000844522/source/com/sap/xi/tf/_MM_RMF_TO_SAP_.java:276: cannot resolve symbol symbol : class DocumentBuilder location: class com.sap.xi.tf._MM_RMF_TO_SAP_ DocumentBuilder builder = factory.newDocumentBuilder(); ^ /usr/sap/XD1/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Map2d519647b0c211e39616000000844522/source/com/sap/xi/tf/_MM_RMF_TO_SAP_.java:277: cannot resolve symbol symbol : class Document location: class com.sap.xi.tf._MM_RMF_TO_SAP_ Document document = builder.parse(in); ^ /usr/sap/XD1/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Map2d519647b0c211e39616000000844522/source/com/sap/xi/tf/_MM_RMF_TO_SAP_.java:278: cannot resolve symbol symbol : class NodeList location: class com.sap.xi.tf._MM_RMF_TO_SAP_ NodeList list = document.getElementsByTagName("I_KOSTL"); // The lookupValue is available as WA tag in the response ^ /usr/sap/XD1/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Map2d519647b0c211e39616000000844522/source/com/sap/xi/tf/_MM_RMF_TO_SAP_.java:279: cannot resolve symbol symbol : class Node location: class com.sap.xi.tf._MM_RMF_TO_SAP_ Node node = list.item(0); ^ /usr/sap/XD1/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Map2d519647b0c211e39616000000844522/source/com/sap/xi/tf/_MM_RMF_TO_SAP_.java:283: cannot resolve symbol symbol : variable returnValue location: class com.sap.xi.tf._MM_RMF_TO_SAP_ returnValue = node.getNodeValue(); ^ /usr/sap/XD1/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Map2d519647b0c211e39616000000844522/source/com/sap/xi/tf/_MM_RMF_TO_SAP_.java:290: cannot resolve symbol symbol : class LookupException location: class com.sap.xi.tf._MM_RMF_TO_SAP_ } catch (LookupException e) { ^ 18 errors

******************************************************************************************************************

so can you please explain, how can i import those files.

Former Member
0 Kudos

Hi

Please provide the function module structure and the UDF code so that I can help you better.

Former Member
0 Kudos

thanks for early response indrajit,


i had given complete UDF, i think in that you can find RFC module as well.



UDF:

*********************************************************************************************************

String return_val = "";

String rfcXML  =  "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"+"<ns0:ZHR_GET_COST_CENTRE" + "xmlns:ns0=\"urn:sap-com:document:sap:rfcfunctions\">"+"<I_PERNR>"+personal_number+"</I_PERNR>"+

"</ns0:ZHR_GET_COST_CENTRE>";

AbstractTrace trace = container.getTrace();

RfcAccessor accessor = null;

ByteArrayOutputStream out = null;

try

{

// 1. Determine a communication channel (Business system + Communication channel)

Channel channel = LookupService.getChannel(BS_SAP_R3,CC_RFC_LOOK_UP_CRMNEXT);

// 2. Get a RFC accessor for the channel.

accessor = LookupService.getRfcAccessor(channel);

// 3. Create an XML input stream that represents the RFC request message.

InputStream inputStream = new ByteArrayInputStream(rfcXML.getBytes());

// 4. Create the XML Payload

XmlPayload payload = LookupService.getXmlPayload(inputStream);

// 5. Execute the lookup.

Payload result = null;

result = accessor.call(payload);

InputStream in = result.getContent();

// 6. Create a DOM structure from the input XML

DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();

DocumentBuilder builder = factory.newDocumentBuilder();

Document document = builder.parse(in);

NodeList list = document.getElementsByTagName("I_KOSTL"); // The lookupValue is available as WA tag in the response

Node node = list.item(0);

if (node != null) {

node = node.getFirstChild();

if (node != null) {

returnValue = node.getNodeValue();

}

}

// 7. To free resources, close the accessor..

if (accessor!=null) {

try {

accessor.close();

} catch (LookupException e) {

trace.addWarning("Error while closing accessor " + e.getMessage() );

}

}

} catch (Exception e) {

trace.addWarning("Error" + e);

}

// 8. return a single id value to the message mapping

return return_val;

**********************************************************************************************************

thanks in advance

Former Member
0 Kudos

Hi

I found problems in this two lines

1. LookupService.getChannel(BS_SAP_R3,CC_RFC_LOOK_UP_CRMNEXT);


The correct one should be


LookupService.getChannel("BS_SAP_R3","CC_RFC_LOOK_UP_CRMNEXT");


2. returnValue = node.getNodeValue();


The correct one should be


return_val = node.getNodeValue();


Here is the complete correct code


String return_val = "";

String rfcXML  =  "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"+"<ns0:ZHR_GET_COST_CENTRE" + "xmlns:ns0=\"urn:sap-com:document:sap:rfcfunctions\">"+"<I_PERNR>"+personal_number+"</I_PERNR>"+"</ns0:ZHR_GET_COST_CENTRE>";

AbstractTrace trace = container.getTrace();

RfcAccessor accessor = null;

ByteArrayOutputStream out = null;

try

{

// 1. Determine a communication channel (Business system + Communication channel)

Channel channel = LookupService.getChannel("BS_SAP_R3","CC_RFC_LOOK_UP_CRMNEXT");

// 2. Get a RFC accessor for the channel.

accessor = LookupService.getRfcAccessor(channel);

// 3. Create an XML input stream that represents the RFC request message.

InputStream inputStream = new ByteArrayInputStream(rfcXML.getBytes());

// 4. Create the XML Payload

XmlPayload payload = LookupService.getXmlPayload(inputStream);

// 5. Execute the lookup.

Payload result = null;

result = accessor.call(payload);

InputStream in = result.getContent();

// 6. Create a DOM structure from the input XML

DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();

DocumentBuilder builder = factory.newDocumentBuilder();

Document document = builder.parse(in);

NodeList list = document.getElementsByTagName("I_KOSTL"); // The lookupValue is available as WA tag in the response

Node node = list.item(0);

if (node != null) {

node = node.getFirstChild();

if (node != null) {

return_val = node.getNodeValue();

}

}

} catch (Exception e) {

trace.addWarning("Error" + e);

}

// 8. return a single id value to the message mapping

return return_val;

Also include these two import in the UDF import section. Click on the button below

include this two

That's it .You are good to go.

Former Member
0 Kudos

Hi Indrajeet,

we are using pi 7.0, please tel me where import these jar files .

  we are not able to c the above image in IR . So please provide me the details it will be gr8 help .

Former Member
0 Kudos

Hi Feroz

I don't have PI 7.0 system but I can see that there is a option called import during UDF creation in XI 3.0. So the same option should be there for 7.0

You have to declare the import like below

Hope this helps.

Former Member
0 Kudos

hi indrajeet,

  previously i had done the same. but still its showing the following error

*********************************************************************************************************

  •                 Errorcom.sap.aii.mapping.lookup.LookupException: Exception during processing the payload.Problem when calling an adapter by using communication channel CC_RFC_LOOK_UP_CRMNEXT (Party: , Service: BS_SAP_R3, Object ID: 960df5cc724c3c059a90c07c11e6ea64) XI AF API call failed. Module exception: 'error while processing the request to rfc-client: com.sap.aii.af.rfc.afcommunication.RfcAFWException: error while processing message to remote system:com.sap.aii.af.rfc.core.client.RfcClientException: functiontemplate from repository was <null>'. Cause Exception: 'error while processing message to remote system:com.sap.aii.af.rfc.core.client.RfcClientException: functiontemplate from repository was <null>'.             

************************************************************************************************************

please help me on this..

Former Member
0 Kudos

Hi

Have you checked the RFC communication channel in RWB? check whether it's red or green.

Stop and start the channel once in RWB.

Also make sure that the function module exists in ECC system. Check the same using t-code SE37

former_member184720
Active Contributor
0 Kudos

Hi Feroz - Did you check the below wiki?

User-defined Mapping Function for RFC Lookup - Code Gallery - SCN Wiki

It should answer all your questions..