Skip to Content
Technical Articles

Login to SAP Using Python

The Programming Language Python gives you many possibilities to use SAP in different ways.

One of them is Logging into SAP without providing Client Number, User Name, or Password.

You might be surprised how this is possible !!

But, to use this kind of feature you need to maintain Client Number, User Name, passwords, etc in your Python Program.

Let me give you more information on this.

There are few Pre-Requisites before we begin.

  • SAP GUI must be installed in your machine. As you are on SCN site I expect you must already know this 😉 ( If not Click here )
  • Python also must be installed in your machine. How to Install( Click Here)

Once you have these Softwares installed in your machine you can write your program or copy the below code and use it.

Obviously, with few modifications as below 😉

<SID> = You need to mention System SID.

<NUM>= Client Number.

<UserName>= User name through which you wanted to log in to SAP.

<Password>= Maintain your User password.(And Update the password whenever there is a change)

Don’t worry I have copied here the same code as shown in the above screenshot.

import os

import tkinter as tk

WIDTH = 200

HEIGHT = 300

root = tk.Tk()

canvas = tk.Canvas(root, height=HEIGHT, width=WIDTH)

canvas.pack()

def myClick1():

    <SID> = os.system('start sapshcut.exe -system=<SID> -client=<NUM> -user=<UserName> -pw=<Password>')

    <SID>.pack()

def myClick2():

    <SID1> = os.system('start sapshcut.exe -system=<SID> -client=<NUM> -user=<UserName> -pw=<Password>')

    <SID1>.pack()

button1 = tk.Button(root, text="<SID>", command=myClick1)

button1.pack()

button2 = tk.Button(root, text="<SID>", command=myClick2)

button2.pack()

root.mainloop()

Note: Before running the above program you need to make sure the Tkinter is installed on your windows and also adjust the height and width as per your requirement.

I have used Visual Studio to write and execute this code.

The above program directly won’t work it will require a few packages that need to be installed using pip. Before executing the above program you need to install pip install Tkinter ( For more information you can click here )

So here you go, When you run the above program you will get something like below as a GUI PopUp.

 

When you click on any of the buttons <SID> or whatever you have mentioned that system will connect and opens up with the maintained credentials. So Enjoy 😀

Here you go !!

 

HOLD ON!!

This is not the end 🙂

You can even use this feature or program for opening any of the URLs in the default browser of your computer, for example, google.com or maybe Monitoring any of the JAVA Portals.

So, to use this you need to include the below:

 

 

and Run the Program :

 

Google.com will be opened in your default browser :

 

If you like this or helps you then please hit Like & Comment And Obviously share 🙂

5 Comments
You must be Logged on to comment or reply to a post.
  • The SAP oriented value-add of this post is to show that sapshcut.exe can open a GUI window + log in on Windows. This program can be called via any language, terminal command, .bat file, etc… So this is not really about Python.

    Nevertheless, I wonder if you have a similar solution targeting “SAP GUI For Java”?

    • Hi Kerem,

      I agree with you that this can be called using any programming Language. So I used Python here and how this can be utilised using Trending Programing Language.

      In this blog I have showed you how can we access particular URL’s using this program Tkinter. There are other features where we can explore more how can we automatically login in any URL’s I’ll share another blog how this can be done.

  • Quite good idea, I am just think how to make the automatic program read the csv or text files from python link with the BAPI for example tcode FB60, I think this program is useful for speed the process  compare with manual entries, my knowledge of python is still a beginner.

    Thanks.