Exercise 4: Call BAPI Method 

Prerequisites

You have determined the interface definition of method GetList of the business object EmployeeAbstract. Or, you can use SAP Assistant to retrieve this definition from the call of function module BAPI_EMPLOYEE_GETLIST.

Procedure

Define the function GetList( ) and write the BAPI call as follows:

Private Function GetList() As Boolean

Dim oEmployee As Object

Dim oReturn As Object

   Screen.MousePointer = vbHourglass 'Activate hour glass

'

'Creating local instance of BO "EmployeeAbstract"

   Set oEmployee = oBAPICtrl.GetSAPObject("EmployeeAbstract")

   If Err.Number <> 0 Then

      MsgBox "No local BO 'Employee' created!", 16, APPID

      Exit Function

   End If

'

'Default Input data

   If Len(Trim$(txtLastName.Text)) = 0 Then

      Select Case MsgBox("Please specify the Last Name", _

                          32 + 1, APPID)

      Case 1    'OK

         Screen.MousePointer = vbDefault 'Deactivate hour glass

         txtLastName.SetFocus

         Exit Function

      Case 2    'Cancel

         txtLastName.Text = "*"

      End Select

   End If

'

'Creating a new table or structure

   Set oPersonalData = oBAPICtrl.DimAs(oEmployee, "GetList", "PersonalData")

'

'Call method "EmployeeAbstract.GetList"

   oEmployee.GetList LastName:=Trim$(txtLastName.Text), _

                    FirstName:=Trim$(txtFirstName.Text), _

                    PersonalData:=oPersonalData, _

                    Return:=oReturn

'

'handling errors at the remote call and checking the return code

   If Not oReturn Is Nothing Then

      If oReturn("Type") <> "" And oReturn("Type") <> "S" Then

         MsgBox oReturn("Type") + oReturn("Code") _

            + vbCrLf + oReturn("Message"), vbOKOnly, APPID

         Exit Function

      End If

   End If

   GetList = True

 

   Call ShowData

End Function

 

You call function GetList by choosing pushbutton "cmdList" or menu item "mnuEmployeeList".

Private Sub cmdList_Click()

   If GetList = True Then

      cmdList.Enabled = False

      mnuEmployeeList.Enabled = False

   End If

   GetList

End Sub

 

Private Sub mnuEmployeeList_Click()

   cmdList_Click

End Sub

 

Function GetList is called after you choose Enter.:

Private Sub txtLastName_KeyPress(KeyAscii As Integer)

   If KeyAscii = vbKeyReturn Then

      KeyAscii = 0

      GetList          'Call Module Function "GetList"

   End If

End Sub

 

Private Sub txtFirstName_KeyPress(KeyAscii As Integer)

   If KeyAscii = vbKeyReturn Then

      KeyAscii = 0

      GetList

   End If

End Sub

How to Continue

Exercise 5: Display Table Data