1

Currently I'm working on how can I start SAP GUI Scripting with Python with the help of Stack Overflow but apparently my SAP GUI does not open the connection page the Page where I enter USERNAME and PASSWORD.

I believe DCG210 is my connection name. Below is a picture to show where I land after I run the Python code:

SAP Logon 740

Also, I would appreciate if anyone have any links to learning SAP GUI Scripting with Python. Thank you!

import win32com.client
import sys
import subprocess
import time


# This function will Login to SAP from the SAP Logon window

def saplogin():

    try:

        path = r"C:\Program Files (x86)\SAP\FrontEnd\SAPgui\saplogon.exe"
        subprocess.Popen(path)
        time.sleep(10)

        SapGuiAuto = win32com.client.GetObject('SAPGUI')
        if not type(SapGuiAuto) == win32com.client.CDispatch:
            return

        application = SapGuiAuto.GetScriptingEngine
        if not type(application) == win32com.client.CDispatch:
            SapGuiAuto = None
            return
        connection = application.OpenConnection("DCG210", True)

        if not type(connection) == win32com.client.CDispatch:
            application = None
            SapGuiAuto = None
            return

        session = connection.Children(0)
        if not type(session) == win32com.client.CDispatch:
            connection = None
            application = None
            SapGuiAuto = None
            return

        session.findById("wnd[0]/usr/txtRSYST-BNAME").text = "USERNAME"
        session.findById("wnd[0]/usr/pwdRSYST-BCODE").text = "PASSWORD"
        session.findById("wnd[0]").sendVKey(0)

    except:
        print(sys.exc_info()[0])

    finally:
        session = None
        connection = None
        application = None
        SapGuiAuto = None


saplogin()
1
  • @wang How about this issue, already has any solution? I meet the same issue Commented Mar 15, 2021 at 8:27

1 Answer 1

1

If you need just to log into SAP you can use this simple snippet and not enter password at all

import subprocess
subprocess.check_call(['C:\Program Files (x86)\SAP\FrontEnd\SAPgui\\sapshcut.exe', '-system=DCG210', '-client=100', '-user=USERNAME', '-pw=PASSWORD'])

Your GUI script only logins to SAP and does nothing more, it is scripting just for scripting.

Sign up to request clarification or add additional context in comments.

1 Comment

sorry I didn't find a file named sapshcut in the folder.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.