cancel
Showing results for 
Search instead for 
Did you mean: 

Calling RFC function module from XI

Former Member
0 Kudos

I have to call a custom RFC function module from XI. From looking in this forum I have a couple of options:

- Use BPM - which I would like to stay away from

- RequestResponseBean

- RFC lookup in message mapping using UDF

- From SP19 I find the blog to do it without a BPM

As I have done an RFC lookup in message mapping before I decided to try this first. I coded the RFClookup as the BAPI call I'd done before (BAPI_CUSTMATINFO_GETLIST) - changing only the XML parameters for the call.

The BAPI call works but the new custom function module (Z_V_PAR_GET_CUSTOMER_DETAIL) returns nothing in the response, when I test on SE37 with the same parameters it works.

QUESTION: Are you limited to the types of function modules you can call in the UDF in message mapping? We have lots of BAPI calls working in our scenarios - but I cannot get the custom function module working.

Code is.............

String m = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><ns0:Z_V_PAR_GET_CUSTOMER_DETAIL xmlns:ns0=\"urn:sap-com:document:sap:rfc:functions\"><IM_COMPANY_CODE>4401</IM_COMPANY_CODE><IM_CUSTOMER>10000030</IM_CUSTOMER><IM_DISTR_CHAN>02</IM_DISTR_CHAN><IM_DIVISION>00</IM_DIVISION><IM_PARTNER_FUNCTION>SP</IM_PARTNER_FUNCTION><IM_SALES_DIS>EU-02</IM_SALES_DIS><IM_SALES_ORG>4401</IM_SALES_ORG></ns0:Z_V_PAR_GET_CUSTOMER_DETAIL>";

try {

// 1. Determine channel (Business system, Communication channel)

Channel channel = null;

channel = LookupService.getChannel("BS_ED1CLNT020", "CC_RFC_LOOKUP_EVEREST");

// 2. Get RFC accessor for a channel

accessor = LookupService.getRfcAccessor(channel);

// 3. Create 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 execute = accessor.call(payload);

InputStream in = execute.getContent();

// Create DOM structure from input XML

DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();

DocumentBuilder builder = factory.newDocumentBuilder();

Document document = builder.parse(in);

t.addInfo(document.toString());

When I use BAPI XML as parameters it works:

String m = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><ns0:BAPI_CUSTMATINFO_GETLIST xmlns:ns0=\"urn:sap-com:document:sap:rfc:functions\"> <CUSTOMERRANGE><item><SIGN>I</SIGN><OPTION>EQ</OPTION><LOW>0010000030</LOW></item></CUSTOMERRANGE></ns0:BAPI_CUSTMATINFO_GETLIST>";

Rest same as above...

Accepted Solutions (0)

Answers (5)

Answers (5)

Former Member
0 Kudos

I can't paste the working code because it was a prototype whilst the correct RFC was being written and I've deleted it now. But as I remember you don't have to do anything special to preserve the spaces. Just enter them between the XML tags as you build the RFC call.

<XML_TAG>EU_02 </XML_TAG>

If this is not working you could assign it to a variable and then use the variable - eg..

String m = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><ns0:Z_V_PAR_WAN_REJECT xmlns:ns0=\"urn:sap-com:document:sap:rfc:functions\"> <I_EMAIL_ADDRESS>" + FROM + "</I_EMAIL_ADDRESS><I_EMAIL_SUBJECT_LINE>" + SUBJECT + "</I_EMAIL_SUBJECT_LINE></ns0:Z_V_PAR_WAN_REJECT>";

Hope this helps

Former Member
0 Kudos

Sorry - wrong link. Here's the correct one:

Former Member
0 Kudos

Lynn,

May I ask how you were able to preserve the trailing blanks on the IM_SALES_DIS field in your data?

I am wrestling with this problem (see my thread: )

Thanks.

henrique_pinto
Active Contributor
0 Kudos

Also, besides the "Remote enabled function" radio button, check whether you have defined any export parameters. XI RFC calls doesn't work very well with tables...

Regards,

Henrique.

Former Member
0 Kudos

I have checked on SE37, Attributes tab "Remote-Enabled Module" is checked. On the Export tab there are export parameters. It works in SE37 so the export parameters should be working, correct?? I am not an ABAP programmer and I didn't write this function, so my knowledge on this is not great.

I have got a try... catch around my code - I just didn't paste it - and no it does not error.

Any more ideas???

Am I correct in saying that I should be able to call any function module from a UDF with this code?

I will now try the other solution Blog: File-RFC-File (without BPM) - this example uses a BAPI too, so maybe I will have problems here too!!!

Former Member
0 Kudos

check in RWB CC monitor to see if any error there.

if not, you might need to debug in the RFC (you would need a abaper to help you), to see if the RFC really gets called.

Yes, that code should be working.

Jayson

Former Member
0 Kudos

Hi Lyn,

To check whether the piece of RFC code is being executed, you can set a remote breakpoint in that piece of ABAP code in that SAP system.

However take note the user that sets the remote breakpoint in the SAP system must be the same user that is specified in the communication channel.

This would give you some idea whether the RFC code is being called when the message mapping takes place.

henrique_pinto
Active Contributor
0 Kudos

Hi Lynn,

make sure to test the RFC in SE37 being logged with the same user that you set up in the comm channel.

It may be lack of authorization.

Also, check the comm channel monitoring, to see if there are any error msgs for your CC.

Regards,

Henrique.

Former Member
0 Kudos

OK I have solved the problem, it was because you have to use the exact field lengths when you pass the parameters.

String m = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><ns0:Z_V_PAR_GET_CUSTOMER_DETAIL xmlns:ns0=\"urn:sap-com:document:sap:rfc:functions\"><IM_COMPANY_CODE>4401</IM_COMPANY_CODE><IM_CUSTOMER>0010000030</IM_CUSTOMER><IM_DISTR_CHAN>02</IM_DISTR_CHAN><IM_DIVISION>00</IM_DIVISION><IM_PARTNER_FUNCTION>SP</IM_PARTNER_FUNCTION><IM_SALES_DIS>EU-02 </IM_SALES_DIS><IM_SALES_ORG>4401</IM_SALES_ORG></ns0:Z_V_PAR_GET_CUSTOMER_DETAIL>";

So for customer I need to pad with preceding zeroes and sales district needed 2 spaces on the end. Should have spotted this sooner - but it is always the stupid errors you have difficulty with.

Thanks for everyone's help.

Former Member
0 Kudos

Are you sure your custom function module is RFC-enabled? Check it in se37.

also put try-catch around the RFC call to catch any possible exception to see what exactly happens. (output the exception information into trace)

Jayson