********************************************************************
FUNCTION ZMM_GET_MM_INFO.
*"----------------------------------------------------------------------
*"*"Local Interface:
*" IMPORTING
*" VALUE(ET_MATNR) TYPE MARA-MATNR OPTIONAL
*" TABLES
*" ET_MATERIAL STRUCTURE ZMM_GET_MM_INFO
*"----------------------------------------------------------------------
IF NOT ET_MATNR IS INITIAL.
SELECT MARA~MATNR MAKT~MAKTX
INTO TABLE ET_MATERIAL
FROM MARA
INNER JOIN MAKT
ON MARA~MATNR = MAKT~MATNR
WHERE MARA~MATNR = ET_MATNR.
ENDIF.
ENDFUNCTION.
********************************************************************
'*******************************************
Sub Excel2SAP()
'**********************************************
'Declare variables
'**********************************************
Dim R3, MyFunc, App As Object
Dim Result As Boolean
'**********************************************'
Make connection from Excel to SAP
'**********************************************
Set R3 = CreateObject("SAP.Functions")
R3.Connection.ApplicationServer = "10.x.x.x"
R3.Connection.System = "ECD"
R3.Connection.SystemNumber = "00"
R3.Connection.Client = "200"
R3.Connection.User = "TestUser"
R3.Connection.Password = "TestPass"
R3.Connection.Language = "EN"
R3.Connection.UseSAPLogonIni = False
'**********************************************
'If connection fails, then exit. No error or warning.
'**********************************************
If R3.Connection.Logon(0, False) <> True Then
Exit Sub
End If
'*****************************************************
'Set FM ZMM_GET_MM_INFO
'*****************************************************
Set MyFunc = R3.Add("ZMM_GET_MM_INFO")
'*****************************************************
'Declare variables (could also be added above) and set Parameters
'*****************************************************
Dim oParam1 As Object
Dim oOutput As Object
Set oParam1 = MyFunc.exports("ET_MATNR")
Set oOutput = MyFunc.Tables("ET_MATERIAL")
'*****************************************************
'Make sure the input cell is formatted as text. This is important for
'leading zero’s. If no leading zero’s, then add them.
'*****************************************************
If Len(Range("A2").Value) < 18 Then
leadingzeros = 18 - Len(Range("A2").Value)
For y = 1 To leadingzeros
Range("A2").Value = "0" & Range("A2").Value & ""
Next y
End If
'*****************************************************
'Input (ET_MATNR)
'*****************************************************
oParam1.Value = Range("A2").Value
'*****************************************************
'Call FM
'*****************************************************
Result = MyFunc.Call
'*****************************************************
'Check result and add to sheet.
'*****************************************************
If Result = True Then
Cells(2, 2).Value = oOutput.Value(1, "MAKTX")
Else
MsgBox MyFunc.EXCEPTION
R3.Connection.Logoff
Exit Sub
End If
'*******************************************
'Logoff
'*******************************************
R3.Connection.Logoff
If Result <> True Then
MsgBox (EXCEPTION)
Exit Sub
End If
End Sub
'*******************************************
Have a question about something in this article? You can receive help directly from the article author. Sign up for a free trial to get started.
Comments (0)