Technology Blogs by SAP
Learn how to extend and personalize SAP applications. Follow the SAP technology blog for insights into SAP BTP, ABAP, SAP Analytics Cloud, SAP HANA, and more.
cancel
Showing results for 
Search instead for 
Did you mean: 
luishammecke
Employee
Employee
This blog describes how to set up the XML structure to successfully call a Function Module or BAPI remotely from SAP Cloud Integration. It shows how the different parameter types like tables, structures and input parameters need to be build in the XML structure. Furthermore, it will be shown how to configure the root element of the XML successfully - even when the Function Module contains XML unfriendly characters like '/'.

The Connection Set-up to the On-Premise system as well as the configuration of the RFC Adapter are seen as prerequisites and are only quickly explained. In order to enable readers to set-up the prerequisites, other blogs are linked.

On-Premise Connection Set-Up


To set-up the connection, please follow jens.neumann's blog: Calling a BAPI in an SAP On-premise system from the Cloud.

If that blog does not do the trick, have a look at the following two blogs, that I also find very helpful:

Short overview of the prerequisite steps and configurations:


First a connection to the On-Premise System needs to be established. In order to do so, a Cloud Connector connection needs to be set up. Once created, resources need to be added to the connection. Those resources are basically paths to Function Modules. So make sure that the Function Module or BAPI is registered as a resource in the Cloud Connector Connection to your Backend System.
On the Cloud side a Destination needs to be created and configured in the BTP Cockpit. The destination basically "picks up" the connection established by the Cloud Connector. That Destination is then used to configure the Destination Field when configuring the RFC Receiver Adapter in SAP Cloud Integration.

Creating the XML Structure


Now, let's take a look at how to create the required target XML Structure to successfully complete a RFC to an on-premise system from SAP Cloud Integration. We will go through the several elements of a XML document step by step and will put the pieces together in the end to have a complete XML document.

Prolog Tag


Generally the Prolog tag for the XML document looks like this:
<?xml version="1.0" encoding="UTF-8"?>

It defines the XML version and the encoding used in the document.

Root Element


The root tag defines the actual Function that is called by the RFC. For the example BAPI BAPI_BUPA_CREATE_FROM_DATA the root tag looks like this:
<ns1:BAPI_BUPA_CREATE_FROM_DATA xmlns:ns1="urn:sap-com:document:sap:rfc:functions">

The namespace of the XML - in this case ns1 - can be chosen relatively freely. From my experience ns1 is commonly used. You just need to make sure to configure the Namespace Mapping in your iFlow. You can get to the Configuration Menu of the iFlow by double clicking on the white Background in the iFlow editor view.


Integration Flow - Runtime Configuration


Sometimes the name of the BAPI or the Function Module contains characters that are not allowed in the XML Syntax, i.e. /PM0/ABT_SVC_INPI_CREATE. In that case (and also in general), the wsdl file of the Function Module will be helpful. To access it enter this URL in your browser (as seen in SAP's Help Portal😞

https://<backend_host>:<backend_https_port>/sap/bc/soap/wsdl11?services=<function_module_name>;

Note: You may need to use your VPN to be in the same network as your backend system. Furthermore, a log-in popup may appear. Enter your user details for the backend system. If you are unsure about the host name and port: Connect to your system, put in the transaction SICF, press Execute (F8), and press the Information on Post and Host button and then use Port and Host for https.


The wsdl file will show the required XML structure including the root element as well as the other input parameters:


wsdl File - Root Element


Therefore, our root element in this case will look like this:
<ns1:_-PM0_-ABT_SVC_INPI_CREATE xmlns:ns1="urn:sap-com:document:sap:rfc:functions">

Simple Parameters


Simple parameters look like this:
<COUNTRY>DE</COUNTRY>

Flags can be set like this:
<IF_CALCULATE>X</IF_CALCULATE>

Structures


Structures in the XML format have one root element and several child elements. The root element's name should be the same as the input parameter for the Function Module, while the child elements are named exactly like in the corresponding structure in the backend system.
<IS_ADDRESS>
<STANDARDADDRESS>X</STANDARDADDRESS>
<CITY>Cologne</CITY>
<POSTL_COD1>40253</POSTL_COD1>
<STREET>Bergstraße</STREET>
<HOUSE_NO>42</HOUSE_NO>
<COUNTRY>DE</COUNTRY>
</IS_ADDRESS>

Tables


Tables contain a root element called like the corresponding input parameter of the Function Module and so called items, that act like the rows of the table and contain the attributes of the structure that the table is based on.
<IT_ADDRESS>
<item>
<STANDARDADDRESS>X</STANDARDADDRESS>
<CITY>Walldorf</CITY>
<POSTL_COD1>69190</POSTL_COD1>
<STREET>Dietmar-Hopp-Allee</STREET>
<HOUSE_NO>16</HOUSE_NO>
<COUNTRY>DE</COUNTRY>
</item>
<item>
<STANDARDADDRESS>X</STANDARDADDRESS>
<CITY>Dortmund</CITY>
<POSTL_COD1>44137</POSTL_COD1>
<STREET>Rheinlanddamm</STREET>
<HOUSE_NO>207/209</HOUSE_NO>
<COUNTRY>DE</COUNTRY>
</item>
</IT_ADDRESS>

Complete Example XML File


<?xml version="1.0" encoding="UTF-8"?>
<ns1:_-PM0_-ABT_SVC_INPI_CREATE xmlns:ns1="urn:sap-com:document:sap:rfc:functions"><COUNTRY>DE</COUNTRY>
<IF_CALCULATE>X</IF_CALCULATE>
<IS_ADDRESS>
<STANDARDADDRESS>X</STANDARDADDRESS>
<CITY>Cologne</CITY>
<POSTL_COD1>40253</POSTL_COD1>
<STREET>Bergstraße</STREET>
<HOUSE_NO>42</HOUSE_NO>
<COUNTRY>DE</COUNTRY>
</IS_ADDRESS>
<IT_ADDRESS>
<item>
<STANDARDADDRESS>X</STANDARDADDRESS>
<CITY>Walldorf</CITY>
<POSTL_COD1>69190</POSTL_COD1>
<STREET>Dietmar-Hopp-Allee</STREET>
<HOUSE_NO>16</HOUSE_NO>
<COUNTRY>DE</COUNTRY>
</item>
<item>
<STANDARDADDRESS>X</STANDARDADDRESS>
<CITY>Dortmund</CITY>
<POSTL_COD1>44137</POSTL_COD1>
<STREET>Rheinlanddamm</STREET>
<HOUSE_NO>207/209</HOUSE_NO>
<COUNTRY>DE</COUNTRY>
</item>
</IT_ADDRESS>
</ns1:_-PM0_-ABT_SVC_INPI_CREATE>

Typical Errors of RFC caused by faulty XML Structure


Get Document Failed


The "Get Document Failed" error message implies that the Function Module or Babi, that has been defined in the XML, could not be found. So double check for spelling mistakes and double check if you use the same root element name as in the wsdl file.

Parameter is missing


If the error message says something in the likes of: "Postal Code cannot be empty", "Postal Code not found" or similar. You either forgot the attribute somewhere (including tables and structures) or you misspelled it. Sometimes this can also be cause by a faulty table/structure root element which then leads to the whole table/structure being empty.

Conclusion


Learning


For me creating the XML structure by hand was quite the pain as it often fails at first and then requires a lot of trail and error to find the root cause (spelling, wrong structure, missing parameters, wrong root element and so on). There is also not much documentation available which does not make it easier. But once you get it to run, RFCs are an easy and convenient way to access backend systems from SAP Cloud Integration.

Feedback


I hope this blog helped you creating the right XML structure for your RFC in SAP Cloud Integration. If you have any ideas, questions, remarks and thoughts feel free to drop a comment or to reach out.

 

 
1 Comment