Exercise 3: Call Function Module 

Prerequisites

The interface definition of the function module RFC_CUSTOMER_GET is known.

Procedure

  1. Specify the function object and add it to the collective object.
  2. '

    'Reference to function object "RFC_CUSTOMER_GET"

    '

       Set theFunc = functionCtrl.Add("RFC_CUSTOMER_GET")

     

  3. Prepare the import parameters for the function call: Use a FOR loop to sort the customer names alphabetically.
  4. Define the display of the R/3 data in the a separate module display_customers.
  5. Declare the parameters you pass to display_customers.

Enter these lines:

'Prepare output to the EXCEL worksheet

'

Worksheets(1).Select

Cells.Clear

 

'

'Declaration

'

Dim customers As Object

Dim returnFunc As Boolean

Dim startzeil As Integer

Dim endcol As Integer

Dim the_name As String

startzeil = 1

 

'Determine the import parameters for the function call

'

For start_char = Asc("A") To Asc("Z")

 

    the_name = Chr$(start_char) + "*"

        '

        theFunc.exports("NAME1") = the_name

        theFunc.exports("KUNNR") = "*"

        returnFunc = theFunc.Call

        die_exception = theFunc.Exception

 

        If returnFunc = True Then

            Set customers = theFunc.tables.Item("CUSTOMER_T")

            endcol = 0

            Call display_customers (the_name, customers, startzeil, endcol)

            startzeil = endcol

            Set customers = Nothing

        Else

            If die_exception = "NO_RECORD_FOUND" Then

               Cells(startzeil, 1) = "No values exist for " + the_name

                startzeil = startzeil + 1

            Else

                MsgBox "Error when accessing function in R/3 ! "

            Exit Sub

            End If

        End If

Next start_char

 

How to Continue

Exercise 4: Display R/3 Data