5 Programming DCOM Clients in VB
This section contains the following topics:
Hints and Recommendations for Programming
Error Handling in the Client Program
Reference to the Type Library
Basic Structure of the Program
Example Program: SalesOrder.vbp
Hints and Recommendations for Programming
Assign R/3 connection parameters (destination, userID,…) to each object instance. Otherwise, the call for the default R/3 system is executed. To each proxy object, a default system is assigned. It is identical with the system against which this object was generated.
Avoid using global instances of proxy objects. Instead, define these objects locally within individual functions. This improves the performance on the MTS, since unused resources are freed in time.
Execute the error handling in your program very thoroughly.
Calling the InitKeys method does not trigger an existancy check for a certain instance in the R/3 database. To do this, call instance-dependent BAPI methods such as CheckExistence or GetDetail for the individual instances.
Prefer transferring parameters to a BAPI or a function module via "named arguments" instead of "position arguments".
Study the example programs delivered with the RFC SDK.
When using the connection parameters (destination, clientID,…) and when calling the methods PutSessionInfo and AdviceRfcGuiSink, you must deviate the object reference to a VB object ("casting"), since due to an MTS bug, marhalling (converting parameters to a form that allows their transfer between processes or machines) cannot be executed otherwise.
Error Handling in the Client Program
For error handling in the client program, it is reasonable to distinguish between three categories of errors:
- Errors connected to the RFC connection.
- Errors at the remote call of function modules that raise the exceptions defined in ABAP.
- Errors at the call of BAPI methods. Usually, BAPIs do not trigger exceptions. To find the errors, you must evaluate the return parameters, which are defined as structures or, very rarely, as tables.
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:
- BAPIRETURN
- BAPIRETURN1
- BAPIRET2
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:
- Creating the instance for a certain object type from R/3.

Setting the connection parameters (Destination, UserID, Password, Language, Client), when the default R/3 System should not to be called.

Defining structure and table parameters using method DimAs (only for importing parameters !)

Filling the input parameters with values.

Calling the object methods (BAPIs or remote functions)

Handling errors and checking the return code information

Displaying and further using the R/3 data. Using the Data Bound Grid Library to represent the data.
Example Program: SalesOrder.vbp
Prerequisites
Visual Basic development environment installed on the client machine.
DCOM proxies installed in the MTS.
Reference to Microsoft ADO Recordset 1.5 Library or higher.
If the client application does not run on the same machine like MTS, so you have to install the Export Package from MTS to the client. See also Exporting MTS Packages.
Procedure
To execute the example program, proceed as follows:
- Choose rfcsdk ®
ccsamp ®
Sales.VB.
- Double-click on the project file SalesOrder.vbp.
The system starts the development environment of Visual Basic and opens the project SalesOrder.
- Choose Project ®
References to create a reference to the generated DCOM proxies.
A list of all available references appears.
- Select the reference to the appropriate Type Library and confirm with OK.

Note:
For information on the naming convention, see Reference to the Type Library.
Choose Start to start the application.
In the initial screen, choose SAP ®
Logon to log on to a system.
The window for entering the logon data appears.

Enter your logon data if they differ from the preset values and confirm with OK.
Show Maintaining Destinations.
In the initial screen, choose SAP ®
PlaceOrder.
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:
