Solved

Login to SAP with VBScript

Posted on 2010-09-01
2
18,310 Views
Last Modified: 2012-06-21
Dear Experts,

Could you please have a look at the attached file and code, it is an VBScript file which is able to login to SAP.

My short question would be that how to continue and for example enter a transaction after?

For example the transaction MMBE, how to call through it?

thanks,
set WshShell = CreateObject("WScript.Shell")
 Set proc = WshShell.Exec("C:\Program Files\SAP\FrontEnd\SAPgui\saplogon.exe")
            Do While proc.Status = 0
            WScript.Sleep 100
      Loop
   Set SapGui = GetObject("SAPGUI")
Set Appl = SapGui.GetScriptingEngine

Set Connection = Appl.Openconnection("Test SAP", True)
Set session = Connection.Children(0)
session.findById("wnd[0]/usr/txtRSYST-BNAME").Text = "User"
session.findById("wnd[0]/usr/pwdRSYST-BCODE").Text = "Password11"
session.findById("wnd[0]/usr/txtRSYST-LANGU").Text = "E"
session.findById("wnd[0]").sendVKey 0

Open in new window

VBS-SAP-login.vbs
0
Comment
Question by:csehz
2 Comments
 
LVL 42

Accepted Solution

by:
sedgwick earned 500 total points
ID: 33575894
0
 
LVL 1

Author Comment

by:csehz
ID: 33575980
Thanks, yes the key is the Script Recording and Playback menu in SAP R3 pressing firstly the ALT-F12.

So if somebody will need such solution in the future, the attached code is able to go to SE16 and download a table content in excel automatically

thanks,
set WshShell = CreateObject("WScript.Shell")
 Set proc = WshShell.Exec("C:\Program Files\SAP\FrontEnd\SAPgui\saplogon.exe")
            Do While proc.Status = 0
            WScript.Sleep 100
      Loop
   Set SapGui = GetObject("SAPGUI")
Set Appl = SapGui.GetScriptingEngine
 
Set Connection = Appl.Openconnection("Test SAP", True)
Set session = Connection.Children(0)
session.findById("wnd[0]/usr/txtRSYST-BNAME").Text = "xxx"
session.findById("wnd[0]/usr/pwdRSYST-BCODE").Text = "xxxxx"
session.findById("wnd[0]/usr/txtRSYST-LANGU").Text = "E"
session.findById("wnd[0]").sendVKey 0
 
If Not IsObject(application) Then
   Set SapGuiAuto  = GetObject("SAPGUI")
   Set application = SapGuiAuto.GetScriptingEngine
End If
If Not IsObject(connection) Then
   Set connection = application.Children(0)
End If
If Not IsObject(session) Then
   Set session    = connection.Children(0)
End If
If IsObject(WScript) Then
   WScript.ConnectObject session,     "on"
   WScript.ConnectObject application, "on"
End If
session.findById("wnd[0]").maximize
session.findById("wnd[0]/tbar[0]/okcd").text = "/nMM03"
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/tbar[0]/okcd").text = "/nSE16"
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/usr/ctxtDATABROWSE-TABLENAME").text = "MARD"
session.findById("wnd[0]/usr/ctxtDATABROWSE-TABLENAME").caretPosition = 4
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/usr/ctxtI2-LOW").text = "PLF6"
session.findById("wnd[0]/usr/ctxtI2-LOW").setFocus
session.findById("wnd[0]/usr/ctxtI2-LOW").caretPosition = 4
session.findById("wnd[0]/tbar[1]/btn[8]").press
session.findById("wnd[0]/mbar/menu[6]/menu[5]/menu[2]/menu[2]").select
session.findById("wnd[1]/usr/sub/1/rad[1,0]").select
session.findById("wnd[1]/usr/sub/1/rad[1,0]").setFocus
session.findById("wnd[1]/tbar[0]/btn[0]").press
session.findById("wnd[1]/usr/ctxtRLGRAP-FILENAME").text = "C:\MARD.xls"
session.findById("wnd[1]/usr/ctxtRLGRAP-FILENAME").caretPosition = 11
session.findById("wnd[1]").sendVKey 0

Open in new window

0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Sending Attachment via CDO 3 69
Compile Error 7 55
Problem to cell option 1 29
OS Selection Menu 1 21
In this tutorial I will show you how to make a simple HTML bar chart with the usage of WhizBase, If you want more information about WhizBase please read my previous articles at http://www.experts-exchange.com/ARTH_5123186.html (http://www.experts-ex…
This script will sweep a range of IP addresses (class c only, 255.255.255.0) and report to a log the version of office installed. What it does: 1.)      Creates log file in the directory the script is run from (if it doesn't already exist) 2.)      Sweep…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question