Can I write a code in Visual Basic to use a BAPI function? For example, BABI_MATERIAL_GETALL ?
By submitting your email address, you agree to receive emails regarding relevant topic offers from TechTarget and its partners. You can withdraw your consent at any time. Contact TechTarget at 275 Grove Street, Newton, MA.
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.
Dig Deeper on SAP ABAP
Related Q&A from Axel Angeli
An SAP user is having difficulty with PERNR iDoc while transporting data from SAP to an external system.continue reading
An SAP user wants to know how to upload data into SAP R/3 when SAP Scripting is not enabled.continue reading
An SAP user is receiving an error message while integrating SAP iDoc PORDCR1 for a purchase order.continue reading
Have a question for an expert?
Please add a title for your question
Get answers from a TechTarget expert on whatever's puzzling you.