Dim R3, App As Object Dim Customers, Customer As Object Dim Result As Boolean '********************************************** 'Create Server object and Setup the connection '********************************************** Sub SAP_Logon() Set R3 = CreateObject("RFC.ServerObject") Set App = R3.Application R3.connection.client = "010" 'R3.connection.user = "SAP*" 'R3.connection.password = "19920706" R3.connection.user = "CPICUSER" R3.connection.password = "19920706" R3.connection.language = "E" R3.connection.Gatewayhost = "" R3.connection.Gatewayservice = "" R3.connection.hostname = "SAPENT" R3.connection.destination = "E40" R3.connection.system = "00" If R3.connection.logon <> True Then App.Quit Exit Sub End If End Sub Sub Command1_Click() SAP_Logon Get_Mara SAP_LOGOFF End Sub Sub SAP_LOGOFF() R3.Close False 'do not save the server object App.Quit End Sub Sub Get_cust() Result = R3.RFC_CUSTOMER_GET(Exception, KUNNR:="*", CUSTOMER_T:=Customers) If Result <> True Then MsgBox (Exception) App.Quit Exit Sub End If '************************************** 'Display table header '************************************** Cells(3, 1) = "Customer ID" Cells(3, 2) = "Customer Name" Cells(3, 3) = "Zip Code" Range(Cells(3, 1), Cells(3, 3)).Font.Bold = True '************************************** 'Display Contents of the customer table ' 'If many customers are expected, use 'the second alternative '************************************** bManyCustomers = False If (bManyCustomers = False) Then i = 4 For Each Customer In Customers.Rows Cells(i, 1) = Customer("KUNNR") Cells(i, 2) = Customer("NAME1") Cells(i, 3) = Customer("PSTLZ") i = i + 1 Next Else For i = 1 To Customers.RowCount Cells(i, 1) = Customers(i, "KUNNR") Cells(i, 2) = Customers(i, "NAME1") Cells(i, 3) = Customers(i, "PSTLZ") Next End If End Sub Sub Get_Mara() Dim Materials, Material As Object Result = R3.Y_RFC_MARA_GET(Exception, MATNR:="S0039*", BWKEY:="1331", BWART:="", T_MARA:=Materials) If Result <> True Then MsgBox (Exception) App.Quit Exit Sub End If '************************************** 'Display table header '************************************** Cells(3, 1) = "Material No" Cells(3, 2) = "Material Name" Cells(3, 3) = "Zip Code" Range(Cells(3, 1), Cells(3, 3)).Font.Bold = True '************************************** 'Display Contents of the customer table ' 'If many customers are expected, use 'the second alternative '************************************** bManyCustomers = False If (bManyCustomers = False) Then i = 4 For Each Material In Materials.Rows Cells(i, 1) = Material("MATNR") Cells(i, 2) = Material("MAKTX") Cells(i, 3) = Material("VERPR") i = i + 1 Next Else For i = 1 To Materials.RowCount Cells(i, 1) = Materials(i, "MATNR") Cells(i, 2) = Materials(i, "MAKTX") Cells(i, 3) = Materials(i, "VERPR") Next End If End Sub
07-12
07-12