Programming DCOM Clients in VB
This section contains the following topics:
Tips and Notes for Programming
Error Handling in the VB Program
Basic Structure of the Program
Tips and Notes for Programming
For Input Paramters (VB
Õ ABAP)When using input parameters to transfer times and dates to ABAP, use the VB data type Date. If necessary, the client can use the same variable to transfer date and time parameters to ABAP.
' example
Dim dDateAndTimeFrom As Date
Dim dDateAndTimeTo As Date
boAppointmentFactory.Create( , _
dDateAndTimeFrom, _ 'ABAP parameter "FROM_DATE"
dDateAndTimeFrom, _ 'ABAP parameter "FROM_TIME"
dDateAndTimeTo , _ 'ABAP parameter "TO_DATE"
dDateAndTimeTo , _ 'ABAP parameter "To_TIME"
.... )
For Output Paramters (ABAP
Õ VB)When using output parameters to return dates and times from ABAP, consider that in VB only one component is initialized: either date or time. The functions below demonstrate how you can separate the parameters into the respective valid components. You can use one of two different versions:
"Traditional" Version:
This version utilizes a conservative implementation using the format function.
The function "AbapDateAndTimeToDate" combines the date (ABAP type D) and
the time (ABAP type T) into a variable Date in VB.
' example:
Dim bo As new SAP.BO
Dim rs As Recordset
Dim dateFrom As Date
bo.GetList rs ' calling a BAPI method
......
dateFrom = AbapDateAndTimeToDate(rs.Fields("DATE_FROM"), rs.Fields("TIME_FROM"))
......
' combine date and time into a VB date
Function AbapDateAndTimeToDate(aDate As Date, aTime As Date) As Date
Dim d As Date
Dim t As Date
d = Format(aDate, "Short Date")
t = Format(aTime, "Long Time")
AbapDateAndTimeToDate = d + t
End Function
The two functions "AbapDateToDate" and "AbapTimeToDate" separately transform the time and date parameters from ABAP into one variable in VB each:
' returns current date in the system-defined short date format
Function AbapDateToDate(aDate As Date) As Date
AbapDateToDate = Format(aDate, "Short Date")
End Function
' returns current time in the system-defined long time format
Function AbapTimeToDate(aTime As Date) As Date
AbapTimeToDate = Format(aTime, "Long Time")
End Function
Optimized Version:
Use the optimized version to improve the performance of the conversion function.
The function "AbapDateAndTimeToDate" combines the date (ABAP type D) and
the time (ABAP type T) into a variable of type Date in VB:
Function AbapDateAndTimeToDate(aDate As Date, aTime As Date) As Date
Dim d As Double
Dim t As Double
d = Fix(aDate)
t = (aTime - Fix(aTime))
AbapDateAndTimeToDate = CDate(d + t)
End Function
The implementation of the function "AbapDateToDate" below enforces the conversion of the date from ABAP to a date of type Date in VB:
' sample:
Dim bo As new SAP.BO
Dim rs As Recordset
Dim dFrom As Date
......
bo.GetList rs 'calling a BAPI method
.....
dFrom = AbapDateToDate(rs.Fields("DATE_FROM"))
.....
Function AbapDateToDate(aDate As Date) As Date
Dim d As Double
d = Fix(aDate)
AbapDateToDate = CDate(d)
End Function
The implementation of the function "AbapTimeToDate" below enforces the conversion of the time from ABAP to a date of type Date in VB:
' sample:
Dim bo As new SAP.BO
Dim rs As Recordset
Dim dTimeFrom As Date
......
bo.GetList rs 'calling a BAPI method
dFrom = AbapTimeToDate(rs.Fields("TIME_FROM"))
......
Function AbapTimeToDate(aTime As Date) As Date
Dim t As Double
t = (aTime - Fix(aTime))
AbapTimeToDate = CDate(t)
End Function
Error Handling in the Client Program
For error handling in the client program, it is reasonable to distinguish between three categories of errors:
The error information of the first two categories is recorded by the DCOM Connector; you can query it in VB. If these types of errors occur, the value of Err.Number is unequal to zero. Execute a query accordingly and let the system display a description of the error from Err.Description.
Note:
In this case, use the statement On error resume next before starting a call.For errors at a BAPI call, apart from the query above, you can access predefined return parameters. The most commonly used ABAP Dictionary structures for return parameters are:
Example: Structure of BAPIRETURN

To be able access generated proxy objects in a VB project, you must create a reference to the corresponding Type Library. Choose Project
® References.The figure below shows the naming convention for the reference you must make to the Type Library:

Basic Structure of the Program
Programming a VB application consists of the following steps:








Prerequisites
Procedure
To execute the example program, proceed as follows:

Note:
For information on the naming convention, see Reference to the Type Library.
Note
: Use the appropriate input data from your system!
Result
The result containing customer-specific data is displayed in a table:

Next: