Development of SAP interface programs using Visual Basic-RFC

Source: Internet
Author: User
Tags sap gui

Use Visual Basic to develop sap InterfacesProgramPreliminary Exploration

The sap r/3 system is the most advanced and stable ERP system in the industry. The proportion of large international and domestic enterprises adopting this system is far ahead of that of other ERP systems. Sap r/3 has a built-in secondary development platform called ABAP, which is similarProgramming Language. ABAP has relatively weak functions in report output (it can only be printed on the screen by row or exported to excel). Therefore, it is often necessary to develop programs externally in daily work. The program interface is used to automatically read data tables (Views) of sap r/3, process them externally, and generate report styles that meet Chinese habits using tools such as Crystal Reports.

Sap r/3 interfaces include RFC, IDOC, and bapi. This document describes the relatively simple RFC (romote function call, remote function call ). The RFC calling principle of the SAP system is actually very simple. There are some C/S systems similar to the three-layer architecture. Third-party customer programs call the standard or custom functions in SAP through interfaces, obtain the data returned by the function for processing and display or print it. The following is a model called by RFC:


This article does not discuss the development of sap r/3 functions, because SAP companies generally have dedicated ABAP developers. If you have the opportunity to access the ABAP platform, you can use the transactionCodeSe37 enters the "function compiler" of the ABAP development platform for function development and testing.

The following uses VB as an example to describe how to develop the RFC for the SAP interface. When installing the sap gui client on the SAP client, be sure to install the included SDK package (the most secure option is full installation ). RFC interface program development mainly uses the "sap. Functions" control to simulate user logon and function calling of the sap gui client in an external program, and then return the function value. See the following program snippets and key annotations (especially test_click ()):

Private sub commandementclick ()
'Define the R/3 user name and password variable (the user name should be permitted by the sap administrator to run the function)
Dim LOGNAME as string * 22, password as string * 22
Call logonr3 (LOGNAME, password) 'to call the sap logon interface program
If logflag then' calls the production and development system switch
Statusbar1.visible = true
Statusbar1.simpletext = "logging on to sap r/3 ..."
Dim r3appserver as string, r3client as string, r3systemno as string
If form2.opprd. value then
'Modify the following server parameters according to the customer's configuration.
R3appserver = "10.3.1.4" 'production system server IP Address
R3client = "800" 'production system group code
R3systemno = "00" 'production System No.
Else
R3appserver = "10.3.3.1" 'Development System server IP Address
R3client = "101"
R3systemno = "00"
End if
Unload form2' releases form2, and all controls and values are unavailable
Set functions = Createobject ("sap. Functions") 'creates the local object of the RFC.
Set connect = functions. Connection 'sets the connection
Connect. applicationserver = r3appserver 'value Server IP Address
Connect. Client = r3client 'value SAP group code
Connect. Language = "ZH" 'sets the SAP system interface to Chinese
Connect. User = trim (LOGNAME) 'value for SAP login Username
Connect. Password = trim (password) 'value for the SAP logon User Password
Connect. systemnumber = r3systemno 'value for the SAP system number
If not connect. Logon (0, true) then' software logs on to sap and determines
Msgbox "failed to log on to sap r/3. Please log on again! ", Vbokonly + vbexclamation," system prompt"
Command1.setfocus
Else' sap login successful
Command1.enabled = false
Command2.enabled = true
Test. Enabled = true
End if

Statusbar1.simpletext = ""
Statusbar1.visible = false
End if
End sub

Private sub command2_click () 'log out of SAP
Connect. Logoff
Command2.enabled = false
Command1.enabled = true
Test. Enabled = false
End sub

Private sub command3_click () 'exit the sap interface demo program
If form1.command2. enabled then
Msgbox "Disconnect the sap r/3 system before exiting! ", Vbokonly + vbinformation," system prompt"
Else
End
End if
End sub

Private sub form_load ()
Command2.enabled = false
Test. Enabled = false
Logoflag = false
End sub

Private sub test_click () 'sap RFC Remote Call processing master demo
Dim getcustomers as object
Dim MERs as object
Dim I as integer
'Remotely run the sap internal function rfc_customer_get through the RFC Interface
'Assign the sap built-in function name to be called
Set getcustomers = functions. Add ("rfc_customer_get ")

Getcustomers. Exports ("kunnr") = "0000000103" 'value to the function entry (Customer Code)
'Assign the query table name to the function entry
Set MERs = getcustomers. Tables ("customer_t ")

If getcustomers. Call then' is successfully invoked, all information entries of the customer are displayed.
For I = 1 to mers MERs. rowcount
Msgbox MERs (I, "kunnr ")
Next I
Else
Msgbox "Search error! Error message: "+ getcustomers. Exception
End if
End sub

RFC call of SAP is the simplest and easiest method in its interface technology. This method is easy to develop and is especially suitable for external report development. However, it is less efficient to query large data volumes. After you have mastered it, You can further learn advanced IDOC and bapi interface development technologies.

    • Source: Skynet

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.