Skip to Content

Have you ever had to execute an RFC-enabled function module from outside the SAP system, for instance from a custom-developed Java application?

If so, then for sure you already know the SAP JCo (SAP Java Connector) Java library, and most probably you have also experienced some difficulties with it. For quite a long time I thought that using JCo is the only way of doing this, just because of the obligatory use of the RFC communication protocol. And finally, I have discovered a nice and smooth way to communicate with SAP “from outside” over HTTP, which means that you can establish the communication easier and more flexibly then ever before.

This blog refers strictly to calling RFC-enabled function modules. If you are interested in sending IDocs to SAP over HTTP, please refer to this blog:

Post IDoc to SAP ERP over HTTP from any application

It also assumes that your Internet Communication Framework (SICF) is configured properly, as the configuration of this framework is not the topic of this blog.

As a prerequisite, go to transaction SICF and locate the following service: sap -> bc -> soap -> rfc. Its description gives you some more details about the functionality: SOAP HTTP HANDLER FOR RFC-CAPABLE FUNCTION MODULES.

/wp-content/uploads/2012/02/20120206_01_121656.png

Now, right-click on that service and choose Test Service, and make sure that you allow SAP to open your web browser (in a popup that appears). Make note of the URL that is opened in the browser. Generally, this URL would look as follows: http://[hostname]:[SICF port]/sap/bc/soap/rfc?sap-client=[client]

Of course, in your particular case it will already contain a concrete host name, port number and client number.

Now that you know the communication URL, use an HTTP client to communicate with SAP. In this example, I will use the SOAP UI tool for this purpose, but it can be any application, including your custom-developed ones, of course. My goal is to execute BAPI_SALESORDER_GETLIST:

/wp-content/uploads/2012/02/20120206_03_121657.png

The screenshot below ilustrates the most important elements of the configuration:

/wp-content/uploads/2012/02/20120206_02_121661.png

  1. Communication method should be POST.
  2. The target URL for the HTTP call is equal to what we checked before when testing the service from SICF:
    http://[hostname]:[SICF port]/sap/bc/soap/rfc?sap-client=[client]
  3. One more thing that actually is not visible there, is the authentication. You have to use an SAP user name and password to authenticate your call. Of course, bead in mind the authorizations required by your particular function module.
  4. In the HTTP call content, declare two namespaces: the SOAP-specific namespace (SOAP-ENV above), and another one that I called RFCDEMO, but it is not the name, but the namespace “urn:sap-com:document:sap:rfc:functions” that really matters. Make sure to spell it correctly, as SAP will not accept any mistakes here. Furthermore, use the standard SOAP-specific structure: Envelope, Header and Body. And finally, in SOAP Body, use the name of the RFC-enabled function module as a node name (use the right namespace), and the parameters, equal to function module parameter names, as subnodes. It is important here that you have to declare Changing and Tables parameters (as empty tags) in the input structure. Otherwise, they will not be returned in the HTTP response. Also note that you do not have to type all the parameters, you can only use the obligatory / necessary ones (as per your requirement).

As a final outcome, you will receive the response from your RFC-enabled function module as the SOAP/HTTP Response.

What is really interesting, you can call several independent function modules without additional effort. You even get separate responses by default. Most importantly, you can use it to execute one particular BAPI and then perform a commit. For instance, if you had to create a sales order and commit it afterwards, you could use the following HTTP request:

<SOAP-ENV:Envelope xmlns:SOAP-ENV=”http://schemas.xmlsoap.org/soap/envelope/” xmlns:RFCDEMO=”urn:sap-com:document:sap:rfc:functions”>

     <SOAP-ENV:Header/>

     <SOAP-ENV:Body>

          <RFCDEMO:BAPI_SALESORDER_CREATEFROMDAT2>

               <SALESDOCUMENTIN/>

               <ORDER_HEADER_IN>

                    <DOC_TYPE>OR</DOC_TYPE>

                    <SALES_ORG>1000</SALES_ORG>

                    <DISTR_CHAN>10</DISTR_CHAN>

                    <DIVISION>00</DIVISION>

               </ORDER_HEADER_IN>

               <CONVERT>X</CONVERT>

               <RETURN/>

               <ORDER_PARTNERS>

                    <item>

                         <PARTN_ROLE>WE</PARTN_ROLE>

                         <PARTN_NUMB>0000001360</PARTN_NUMB>

                    </item>

               </ORDER_PARTNERS>

          </RFCDEMO:BAPI_SALESORDER_CREATEFROMDAT2>

          <RFCDEMO:BAPI_TRANSACTION_COMMIT/>

     </SOAP-ENV:Body>

</SOAP-ENV:Envelope>

One more important thing to notice here is that whenever you have to pass an entry to a TABLES parameter, use the <item> tag to define an array line.

There are few more things to consider when using the approach described:

  1. In the examples above I only used standard BAPIs, but this will work equally well with any RFC-enabled function module.
  2. Unfortunately, just like with calling RFC-enabled function modules in the standard approach (from another SAP system, or over JCo), there is no monitoring tool to analyze these messages. The only status information you have is the response from the function module, that you get as the actual HTTP response. Moreover, you can also enable Logging and Debugging for such scenario. Please refer here for more details:
    http://help.sap.com/saphelp_nw70ehp1/Helpdata/EN/78/2bff7a01bd11d5991400508b6b8b11/content.htm
  3. In general, the solution described here should not be considered as an alternative to standard RFC processing, whenever SAP PI is in the landscape. It is safer to use RFC adapter, or encapsulate several BAPIs and additional logic in an ABAP Proxy. However, if you are not able to use SAP PI nor SAP BC for some reason, you might find my solution useful.
To report this post you need to login first.

7 Comments

You must be Logged on to comment or reply to a post.

  1. Olivier CHRETIEN
    Hi,

    What you describe is the first SAP abap implementation of web services which started on WAS 6.20. It works perfectly but it is supposed to be obsolete since WAS 6.40.
    The new implementation is much cleaner (one different URL for each web service) and much more powerful (External interface, WS-Security) and so on…

    Regards,
    Olivier

    (0) 
    1. Grzegorz Glowacki Post author

      Hi Olivier,

      Thanks for your comment. I agree that the new implementation has many advantages over this one. Still, I believe the old one is at least worth knowing. Moreover, some customers still use older system versions, so they also might find it useful.

      Regards,

      Greg

      (0) 
      1. jim thomas

        Hi Greg,

        We are using WAS 6.20. I having problem getting a reponse when calling BAPI.

        I am using SOAP UI to call BAPI. Can you please help?

        Regards,

        James

        (0) 
        1. Grzegorz Glowacki Post author

          Hi James,

          It is really hard to say with so few details, but I guess the key for your solution is already included in the blog:

          It is important here that you have to declare Changing and Tables parameters (as empty tags) in the input structure. Otherwise, they will not be returned in the HTTP response.

          Regards,

          Greg

          (0) 
      2. Martin Maruskin

        Hi Grzegorz / Olivier,

        As per posts above I understand that this method of calling SAP web service called RFC is quilel old fashioned one – style of WAS 62. Can you please briefly describe what would be newer technology as of WAS 640? Can you poin tme ot some blogs/documentation about the newest technology?

        Grzegorz: great blog, all worked for me at first attempt!

        thanks,

        m./

        (0) 
  2. Khaled BOUKARI

    Hi Grzegorz Glowacki,

    I’m trying to implement this example using my own developped Function Module and I’m always getting an empty response in the soap client.

    I’m using SOAPUI and here is my request:

    <SOAP-ENV:Envelope xmlns:SOAP-ENV=”http://schemas.xmlsoap.org/soap/envelope/

    xmlns:RFCDEMO=”urn:sap-com:document:sap:rfc:functions”>

    <SOAP-ENV:Header/>

    <SOAP-ENV:Body>

    <RFCDEMO:ZTEST_FM_OPERATIONS>

    <IV_PARAM_1>1</IV_PARAM_1>

    <IV_PARAM_2>3</IV_PARAM_2>

    <RV_RESULT_1/>

    <RV_RESULT_2/>

    </RFCDEMO:ZTEST_FM_OPERATIONS>

    </SOAP-ENV:Body>

    </SOAP-ENV:Envelope>

    If I enter wrong user and password for the authentication or if I deactivate the service, I can get the exception message. But if I enter the right parameters and the service is active then I get an empty message.

    Do you have any idea about that?

    Thanks for your support.

    (0) 
    1. Grzegorz Glowacki Post author

      Hi Khaled,

      Try removing the RV parameters from your request. As far as I know, only tables parameters have to be added that way.

      Regards,

      Grzegorz

      (0) 

Leave a Reply