Cheney Wang
Cheney Wang

Reputation: 11

How to log into SAP silently using win32com methods?

I have a question about SAP silent logon which I implemented using win32com this way

from win32com.client import Dispatch

R3 = Dispatch("SAP.Functions")
R3.Conn.System = 'xxx'
R3.Conn.Client = '100'
# other values needed to pass to R3.Conn
R3.Conn.logon #here is the problem

In VB i can use R3.Conn.Logon(1, True) to make logon siliencely. But in Python Logon seems not to be a method and do not allow me to pass parameters to it.

I tried using R3.Conn.Logon(1, True) in Python, but it returned an error

Logon was not callable.

How should I call silent logon in Python?

Thanks

Upvotes: 1

Views: 1867

Answers (1)

Lorenzo
Lorenzo

Reputation: 187

This works for me. Still experimenting, I want to add field selection and of course a filter to the RFC_READ_TABLE. But the connection works.

from win32com.client import Dispatch

Functions = Dispatch("SAP.Functions")

Functions.Connection.Client = "000"
Functions.Connection.ApplicationServer = "your server"
Functions.Connection.Language = "EN"
Functions.Connection.User = "you"
Functions.Connection.Password = "your pass"
Functions.Connection.SystemNumber = "00"
Functions.Connection.UseSAPLogonIni = False

if (Functions.Connection.Logon (0,True) == True):
    print("Logon OK")
    RfcCallTransaction = Functions.Add("RFC_READ_TABLE")
    strExport1 = RfcCallTransaction.exports("QUERY_TABLE")
    strExport2 = RfcCallTransaction.exports("DELIMITER")
    strExport3 = RfcCallTransaction.exports("ROWSKIPS")
    strExport4 = RfcCallTransaction.exports("ROWCOUNT")
    tblOptions = RfcCallTransaction.Tables("OPTIONS")
    #RETURNED DATA
    tblData = RfcCallTransaction.Tables("DATA")
    tblFields = RfcCallTransaction.Tables("FIELDS")


    strExport1.Value = 'AGR_DEFINE'
    strExport2.Value = ";"
    strExport3.Value = 0
    strExport4.Value = 10

    if RfcCallTransaction.Call == True:
        print ("Function call successful")
        #print (tblData.RowCount)
        j = 1
        while j < tblData.RowCount:
            print (tblData(j,"WA"))
            j = j + 1

Upvotes: 1

Related Questions