Example Application with the Function Control 

This example application demonstrates almost all the objects discussed and several of their properties and methods. The application gets a list of customers from the R/3 System and prints attributes for each customer (for example, name and ZIP code). The function interface is:

RFC_CUSTOMER_GET

IMPORT

   

Name (NAME1)

     
       

IMPORT

   

Customer-Number (KUNNR)

       

TABLES

   

CUSTOMER_T (RFCKNA1)

This function uses selection criteria (name and customer number) to retrieves a set of customers, as in the SQL query:

select * from CUSTOMER_T where NAME1=Name

and KUNNR=Customer Number

The table has the following structure (all fields are of type RFC_CHAR):

Customer Table Structure:

KUNNR

ANRED

NAME1

PFACH

STRAS

PSTLZ

ORT01

TELF1

TELFX

The following example accesses the remote function by adding Function objects to the Functions collection object:

Declare object variables:

Dim Functions as Object

Dim GetCustomers as Object

Dim Customers as Object

Create the Function control (that is, the high-level Functions collection):

Set Functions = CreateObject ( " SAP.Functions " )

Indicate what R/3 System you want to log on to:

Functions.Connection.Destination = " B20 "

Set the rest of Connection object values:

......

Log on to the R/3 System:

Functions.Connection.Logon

if Functions.Connection.Logon (0, True) <> True then

MsgBox "Cannot logon!"

End If

Retrieve the Function object (the Connection object must be set up before Function objects can be created):

Set GetCustomers = Functions.Add("RFC_CUSTOMER_GET")

Set the export parameters (here, get all customers whose names start with J):

GetCustomers.Exports("NAME1") = "J*"

GetCustomers.Exports("KUNNR") = "*"

Call the function (if the result is false, then display a message):

If GetCustomers.Call = True then

There are two ways of accessing the table:

Set Customers = GetCustomers.Tables(1)

Set Customers = GetCustomers.Tables( " Customers " )

Print Customers (Customers.rowcount, " KUNNR " )

Print Customers (Customers.rowcount, " NAME1 " )

Else

MsgBox " Call Failed! error: " + GetCustomers.Exception

End If

Functions.Connection.Logoff

A variation of this code can be used for dynamic calls. See Variation using the Dynamic Calling Convention.