Q

Visual Basic code for a BAPI function

Our expert provides code for BAPI functions to use in Visual Basic.

Can I write a code in Visual Basic to use a BAPI function? For example, BABI_MATERIAL_GETALL ?
Thank you.

Sure you can. The following code calls RFC_RAD_TABLE_ENTRIES from VBA:

' Example calling BAPI RFC_GET_TABLE_ENTRIES
Option Explicit
Public Functions As SAPFunctionsOCX.SAPFunctions
Private LogonControl As SAPLogonCtrl.SAPLogonControl
Private R3Connection As SAPLogonCtrl.Connection
Dim Func As SAPFunctionsOCX.Function
Public iTABLE_NAME  As SAPFunctionsOCX.Parameter
Public eNUMBER_OF_ENTRIES  As SAPFunctionsOCX.Parameter
Public tENTRIES  As SAPTableFactoryCtrl.Table

Private Sub Main()
    Dim ix As Integer
    Dim retcd As Boolean
    Dim SilentLogon As Boolean
    Set LogonControl = CreateObject("SAP.LogonControl.1")
    Set Functions = CreateObject("SAP.Functions")
    Set TableFactory = CreateObject("SAP.TableFactory.1")
    Set R3Connection = LogonControl.NewConnection
    R3Connection.Client = "000"
    R3Connection.ApplicationServer = "192.168.69.111"
    R3Connection.Language = "EN"
    R3Connection.User = "DEVELOPER"
    R3Connection.Password = "19920607"
    R3Connection.System = "WAS"
    R3Connection.SystemID = "$WebAS"
    R3Connection.SystemNumber = "18"
    R3Connection.UseSAPLogonIni = False
    SilentLogon = True
    
    retcd = R3Connection.Logon(0, SilentLogon)
    If retcd <> True Then MsgBox "Logon failed": Exit Sub
    Functions.Connection = R3Connection
    
    Set Func = Functions.Add("RFC_GET_TABLE_ENTRIES")
    Set iTABLE_NAME = Func.Exports("TABLE_NAME")
    Set eNUMBER_OF_ENTRIES = Func.Imports("NUMBER_OF_ENTRIES")
    Set tENTRIES = Func.Tables("ENTRIES")
    iTABLE_NAME.Value = "TCURR"
    Func.Call
    Debug.Print eNUMBER_OF_ENTRIES
    For ix = 1 To tENTRIES.RowCount
        Debug.Print tENTRIES(ix, 1)
    Next
    R3Connection.logoff
End Sub

To learn more have a look in the mySAP section of logosworld.com or read the R/3 Guide to EDI, IDocs, ALE and Interfaces. Here is also a short document that explains the code in more detail.

This was last published in July 2006

Dig Deeper on SAP ABAP

PRO+

Content

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

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

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.

-ADS BY GOOGLE

SearchManufacturingERP

SearchOracle

SearchDataManagement

SearchAWS

SearchBusinessAnalytics

SearchCRM

SearchContentManagement

SearchFinancialApplications

Close