Home > SAP software/management Tips > SAP tips and best practices > Function module for Web RFC
SAP Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 

SAP TIPS AND BEST PRACTICES

Function module for Web RFC


12.13.2001
Rating: -4.00- (out of 5)


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


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:

http://bernd/scripts/wgate.dll?~Service=xgwfc&function=iac_calculator&f1=33&f2=44&op=%2b

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:

Parameter_name=Value

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.



Code

FUNCTION IAC_CALCULATOR.
*"-----------------------------------------------------------------
*"*"Local interface:
*"     EXPORTING
*"        VALUE(CONTENT_TYPE) LIKE W3PARAM-CONT_TYPE
*"        VALUE(CONTENT_LENGTH) LIKE W3PARAM-CONT_LENGTH
*"     TABLES
*"        QUERY_STRING STRUCTURE W3QUERY
*"        HTML STRUCTURE W3HTML
*"        MIME STRUCTURE W3MIME
*"-----------------------------------------------------------------

data: feld1(50) type c,
      feld2(50) type c,
      feld3(50) type c,
      fop.
  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.
    endcase.
  endloop.

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

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

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.


Rate this Tip
To rate tips, you must be a member of SearchSAP.com.
Register now to start rating these tips. Log in if you are already a member.


Submit a Tip




Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   



RELATED CONTENT
SAP tips and best practices
Minimizing business disruptions during an SAP upgrade or implementation
Retrieving content from an SAP workflow attachment
Updating URLs in SAP SRM
How to change default settings in SAP SRM
What are the benefits of implementing SAP SRM?
Increase column width in a transaction screen
Updating an RT table entry in SAP HR Payroll -- without the ADDWTE option
Is this the quickest way to find a BADI?
Adding custom fields for retail product comparisons in SAP BW
Improving performance with ABAP Objects in SAP Workflow

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary

DISCLAIMER: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.



NetWeaver SAP White Papers
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Site Map




All Rights Reserved, Copyright 2000 - 2009, TechTarget | Read our Privacy Policy
SearchSAP.com is a search service provided by TechTarget and is completely
independent of and not affiliated with SAP AG.
  TechTarget - The IT Media ROI Experts