Problem solve Get help with specific problems with your technologies, process and projects.

Function module for Web RFC

The RFC channel is one method by which the SAPGUI can communicate with the R/3 System.

The RFC channel is one method by which the SAPGUI can communicate with the R/3 System. This excerpt, taken from...

SAP R/3 on the Internet, shows how to call a special function module for the R/3 System with the RFC channel.

With the RFC channel, you can call special function modules of the R/3 System. Within the R/3 System, these modules must be identified as RFC function modules. In a Web-RFC connection, the ITS redirects the data delivered by the function module to the Web server without changing it in any way. Accordingly, these function modules must return a complete HTML page or a binary object. External templates, such as those for dialog applications, are not presently available. The fucntion module must work like traditional CGI applications.

Although this method is very flexible, it is also more complex than dialog programming. A Web-RFC module features a predefinted interface because transfer tables must store both input and output data.

The ITS stores input data in an array and transfers it to the function module as an internal table. The table parameter is called QUERY_STRING, and its structure corresponds to the dictionary structure W3QUERY. This table stores all the fields of the current data context, both system fields and application data, in name-value pairs.

Table HTML (structure W3HTML) for HTML pages and MIME (structure W3MIME) for binary data handle the return of values. Fill the CONTENT_TYPE field with the type identification that conforms to HTML. If the module delivers binary data, you must also fill the CONTENT_LENGTH field with the exact length of the binary object.

Calling such a function module requires a URL in the following form:


The URL begins with the obligatory specification of the protocol (http://). It includes the name of the Web server (bernd) and the call of teh ITS (/scripts/wgate.dll). The server installed at your site will undoubtedly have a different name. However, a standard installation includes the access to the ITS given above and will likely correspond to the particulars of your system.

When you call the Web-RFC service, you must transfer some parameters. Append the parameters to the URL. A question mark separates the address portion of the URL from the parameters. Specify parameters in the following form:


The ampersand (&) separates individual parameters from each other. The first parameter (~Service=XGWFC) is intended for the ITS. It informs the ITS which service it should execute. This special service is designed to call a function module in the R/3 System. The next parameter (_function=its_calculator) transfers the name of the function module. The underscore (_) belongs to the parameter name. All additional parameters (f1=33, f2=44 and op=%2b) are redirected to the function module and evaluated there. Please note that a plus sign (+) has a special meaning within a URL, and you may not use it in a URL for the value to the op parameter. In place of the plus sign, use the internal HTML appearance %2b. No problems occur with the other three operands ("-", "*", "/").

Despite its simple functions, the function module is rather complicated. It requires great effort to evaluate the parameters.

*"*"Local interface:
*"     TABLES

data: feld1(50) type c,
      feld2(50) type c,
      feld3(50) type c,
  refresh html.
  refresh mime.
  content_type = 'text/html'.
  html = '<html>'.
  append html.
  html = '<body>'.
  append html.
  html = '<h1>calculator via rfc</h1>'.
  append html.
  html = '<hr>'.
  append html.
  loop at query_string.
    case query_string-name.
      when 'F1'.
        feld1 = query_string-value.
      when 'F2'.
        feld2 = query_string-value.
      when 'OP'.
        fop   = query_string-value.

  case fop.
    when '+'.
      feld3 = feld1 + feld2.
    when '-'.
      feld3 = feld1 - feld2.
    when '*'.
      feld3 = feld1 * feld2.
    when '/'.
      IF FELD2 <> 0.
        FELD3 = FELD1 / FELD2.
        FELD3 = 'ERROR'.

  concatenate feld1 ' ' fop ' ' feld2 ' = ' feld3 into html.
  append html.
  html = '</body>'.
  append html.
  html = '</html>'.
  append html.

The internal table QUERY_STRING handles the input parameters for all Web-capable function modules called with RFC. The table consists of the NAME and VALUE fields. Input parameters are transferred in this table. These, however, are not only, however, the parameters in the URL, but also some ITS fields. A tilde (~) in front of the name identifies these fields. The above example does not evaluate these fields.

The example creates a simple HTML page and fills it with the results of the calculation. In actual practice, a function module called in this manner can perform very complex tasks.

To read more of SAP R/3 on the Internet, or to buy the book, click here.

This was last published in December 2001

Dig Deeper on SAP Basis administration and NetWeaver administration



Find more PRO+ content and other member only offers, here.

Start the conversation

Send me notifications when other members comment.

By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Please create a username to comment.