Skip to Content
0
Former Member
Nov 29, 2006 at 04:05 PM

ASPX Bad Variant Type

1232 Views

This code is simply to prove my connection to SAP is working. So far, I'm unable to get it to work without getting the "Bad Variant Type" error.

<%@ Page Language="VB" Debug="true" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%
    Dim fc As Object
    Dim sapConn As Object
    Dim PARTNERS_TAB As Object
    Dim RETURN_TAB As Object
    Dim Z_BAPI_FIND_CUSTOMERS As Object
    Dim msg As String
    Dim fld_type As String
    Dim count As Integer
    Dim index As Integer
    Dim index2 As Integer
    Dim cnt_sold_to As Integer
    Dim cnt_ship_to As Integer
    Dim retcd As Integer

    msg = "start" & "<BR>"
    fc = CreateObject("SAP.Functions")
    fc.LogLevel = 9
    fc.LogFileName = "C:temperrors.txt"
    sapConn = CreateObject("SAP.Logoncontrol.1")
    fc.Connection = sapConn.NewConnection()
    '************************************** 
    'Pass the name of the system 
    '************************************** 
    fc.Connection.System = "TST"
    fc.Connection.SystemNumber = "02"
    '************************************** 
    'Pass the name of the Server 
    '************************************** 
    fc.Connection.ApplicationServer = "server.fqdn.net"
    '************************************** 
    'Pass the name of the Client 
    '************************************** 
    fc.Connection.client = 100
    '************************************** 
    'Pass the name of the USER 
    '************************************** 
    fc.Connection.user = "username"
    '************************************** 
    'Pass the name of the Password 
    '************************************** 
    fc.Connection.Password = "password"
    '************************************** 
    'Pass the name of the Language 
    '************************************** 
    fc.Connection.language = "EN"

    '************************************** 
    'Log On to the SAP System 
    '**************************************
    
    retcd = fc.Connection.Logon(0, True)
    If (retcd = False) Then
        msg = msg & "SAP Logon Failed." & "<BR>"
    Else
        msg = msg & "logon success / setting vars" & "<BR>"
        Z_BAPI_FIND_CUSTOMERS = fc.Add("Z_BAPI_FIND_CUSTOMERS")
   
        Z_BAPI_FIND_CUSTOMERS.Exports("SOLDTO_NAME") = "Customer Name"
        Z_BAPI_FIND_CUSTOMERS.Exports("SOLDTO_CITY") = "CHICAGO"
        'Z_BAPI_FIND_CUSTOMERS.Exports("SOLDTO_NBR")
        Z_BAPI_FIND_CUSTOMERS.Exports("SHIPTO_NAME") = "Customer Name"
        Z_BAPI_FIND_CUSTOMERS.Exports("SHIPTO_CITY") = "BAYONNE"
        Z_BAPI_FIND_CUSTOMERS.Exports("SHIPTO_STATE") = "NJ"
        'Z_BAPI_FIND_CUSTOMERS.Exports("SHIPTO_NBR")

        msg = msg & "calling func" & "<BR>"
        If (Z_BAPI_FIND_CUSTOMERS.Call() <> True) Then
            msg = msg & "func fail" & "<BR>"
        Else
            msg = msg & "func success" & "<BR>"
            RETURN_TAB = Z_BAPI_FIND_CUSTOMERS.Tables("RETURN_TAB")
            fld_type = RETURN_TAB.Value("TYPE")
            If ((fld_type = "M") Or (fld_type = "N")) Then
                msg = msg & fld_type & " " & RETURN_TAB.Value("MESSAGE") & "<BR>"
            Else
                msg = msg & "parameters are correct <BR>"
                PARTNERS_TAB = Z_BAPI_FIND_CUSTOMERS.Tables("PARTNERS_TAB")
                ' Results
                count = PARTNERS_TAB.Rows.Count
                msg = msg & "partner rows: " & CStr(count) & "<BR>"
                If (count > 2) Then ' we have more than one soldto or shipto
                    cnt_sold_to = 0
                    cnt_ship_to = 0
	     
                    For index = 1 To PARTNERS_TAB.Rows.Count
                        If (PARTNERS_TAB.Value(index, "PARTN_ROLE") = "AG") Then
                            cnt_sold_to = cnt_sold_to + 1 ' PARTN_ROLE = "AG"
                        Else
                            cnt_ship_to = cnt_ship_to + 1 ' PARTN_ROLE = "WE"
                        End If
                    Next ' go to next record in partner_tab
                    msg = msg & "sold to: " & CStr(cnt_sold_to) & " ship to: " & CStr(cnt_ship_to) & "<BR>"
                End If ' count of partners_tab > 2 we *may* need to do something about it here - fix me
                msg = msg & "<table>"
                For index = 1 To PARTNERS_TAB.Rows.count
                    msg = msg & "<tr>"
                    For index2 = 1 To 8
                        msg = msg & "<td>" & PARTNERS_TAB.Value(index, index2) & "</td>"
                    Next
                    msg = msg & "</tr>"
                Next
                msg = msg & "</table>"
                'If ((cnt_sold_to = 1) And (cnt_ship_to = 1)) Then ' we only have one soldto and one shipto
                '    Results.Visible = False
                'Else ' we have more than one shipto or soldto - fix me
            End If
        End If
    End If
    msg = msg & "<br>DONE!"
    Response.Write(msg)
    Response.End()
%>

The error occurs when I make the call to fc.add.