Development of SAP interface program using VB

Source: Internet
Author: User
Tags sap gui
Author: Feng Qiang Source: Tianji development Tianji link: http://dev.yesky.com/31/2200031.shtml sap r/3 system is the industry's most advanced, the most stable ERP system, the proportion of large international and domestic enterprises adopting this system is far ahead of the sum of other ERP systems. Sap r/3 has a built-in secondary development platform called ABAP, which is a programming language similar to Cobol. 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 transaction code se37 to enter 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.

Program VB6 project package: http://www.iptver.com/download/share/20051016_SAP_RFC_Example_VB.rar

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.