Visual Basic Calling SAP - Using BAPI Calls: - Arjun
Visual Basic Calling SAP - Using BAPI Calls: - Arjun
The example is a program developed in Visual Basic. It gives an idea about the hierarchy that
needs to be followed when calling BAPI.
The example consists of three BAPI calls namely, for PO, GRN and Sales Order creation. The
code is also available for download.
Create a new project in VB and add 3 normal forms and a MDI form(Main form from where
child forms will be called). Three forms namely for PO Order, GRN, and Sales Order creation.
Also add SAP BAPI Control to the project to have relevant library get loaded into project.
MDI Screen:
Form PORDER:
Form GRN:
', _
'HEADERADDDATARELEVAN:=" ", SKIPITEMSWITHERROR:=" ", ITEMADDDATARELEVANT:=" "
'X = ORETURN.Value("message")
'If X = "" Then
' MsgBox "Transaction Complete."
'Else
' MsgBox X
'End If
MsgBox (ORETURN.Columns("MESSAGE").Value(1))
End Sub
Private Sub Command2_Click()
OCONN.LOGOFF
End Sub
Private Sub Command3_Click()
Call Form_Load
End Sub
Private Sub Form_Load()
Text1(0) = Format(Now, "mm/dd/yyyy")
Text1(1) = Format(Now, "mm/dd/yyyy")
'Text1(2).SetFocus
Set BAPICTRL = CreateObject("SAP.BAPI.1")
Set OCONN = BAPICTRL.Connection
OCONN.LOGON
Set BOORDER = BAPICTRL.GetSAPObject("GoodsMovement")
Set OCODE = BAPICTRL.DimAs(BOORDER, "CreateFromData", "GoodsmvtCode")
Set OITEMIN = BAPICTRL.DimAs(BOORDER, "CreateFromData", "GoodsmvtItem")
Set OHEADER = BAPICTRL.DimAs(BOORDER, "CreateFromData", "GoodsmvtHeader")
Set ORETURN = BAPICTRL.DimAs(BOORDER, "CreateFromData", "RETURN")
End Sub
Private Sub Form_Unload(Cancel As Integer)
OCONN.LOGOFF
End Sub
Form SALESORDER:
End Sub