Programming DCOM Clients in VB

This section contains the following topics:

dot.gif (151 Byte)   Tips and Notes for Programming

dot.gif (151 Byte)   Formating Dates and Times

dot.gif (151 Byte)   Error Handling in the VB Program

dot.gif (151 Byte)   Reference to the Type Library

dot.gif (151 Byte)   Basic Structure of the Program

dot.gif (151 Byte)   Example Program

dot.gif (151 Byte)   Tutorial

Tips and Notes for Programming

 

Formatting Dates and Times

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

 

Reference to the Type Library

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:

Example Program: Sales.vbp

Prerequisites

 

Procedure

To execute the example program, proceed as follows:

  1. Choose rfcsdk ® ccsamp ® Sales.VB.
  2. Double-click on the project file Sales.vbp.
    The system starts the development environment of Visual Basic and opens the project SalesOrder.
  3. Choose Project ® References to show or create a reference to the generated DCOM proxies.
    A list of all available references appears.
  4. If not created, select the reference to the appropriate Type Library and confirm with OK.
  5. Note: For information on the naming convention, see Reference to the Type Library.

  6. Choose Start to start the application.
  7. In the initial screen, choose SAP ® Logon to log on to a system.
    The window for entering the logon data appears.
  8. Enter your logon data if they differ from the preset values and confirm with OK.
    Show Maintaining Destinations.
  9. In the initial screen, choose SAP ® Place Order.
  10. Enter valid values for the input parameters.
    The example program also contains functions for verifying certain entries.

Note: Use the appropriate input data from your system!

 

Result

The result containing customer-specific data is displayed in a table:

Next:

Tutorial