on 01-23-2008 8:36 AM
Hello,
has anyone ever found out if you can catch the proper error when you cant logon to SAP via VBscript due to user issues?
There is the <connection>.isconnected() object, but that only returns 1 for connected and 8 for disconnect.
And also the <connection>.LastError pbject, but I havent been able to get anything out of it at all.
I am really looking to get the information you get in the SAPGUI status bar like "user locked" or "out of date range" etc ...
Thanks,
Andi
I couldnt test it yet, but this might help you:
Property messageAsPopup As Boolean (Read only)
Description: Some messages may be displayed not only on the
statusbar but also as a pop-up window. In such
cases, this property is set to True so that a
script knows it has to close a pop-up to continue.
More information can be found in the SAP Gui scripting manual.
Good luck.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Andreas,
Did you got any solution on how to capture RFC logon error?
I am able to login in SAP GUI Logon where as while connecting the same from vb script its not working. The below line returns as false and the isconnected value is 8.
If objconn.Logon(0, True) <> True Then
I couldn't able to figure out the exact issue using the vb script. And if anything can be done from SAP server end to check and trace the error also it will be helpful.
Thanks
Regards,
Prakash
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Andreas,
I understand that this is quite an old thread, but since I went through some troubles myself with a similar question the last few weeks, let me share my findings with you or whoever else might be in a similar situation.
First of all: my engine was a VB.net scripting engine, so a newer generation as pure VB script we had back 4 years ago. However, I found it very cumbersome to write code, debug, track and trace it especially in a scenario like connecting to SAP, passing parameters, tables etc. back and forth.
So, I decided that the scripting avenue was not good enough a road for me to take.
Instead, I chose standard VB (I ended up using both VBA and VB.net with the Visual Studio Express) and found this to be a completely different game.
Starting with VBA, the most helpful post in this respect was:
http://klanguedoc.hubpages.com/hub/Silent-Connection-with-SAPLOGON-with-RFCSDK-Example-RFC-Excel-VBA
Taking this to VB.net and to the next level (calling an RFC) was relatively easy after this, following this article:
http://help.sap.com/saphelp_nw04/helpdata/en/63/5d4f73c4a411d194ae00a0c94260a5/content.htm
Granted, the VB.net syntax is a bit different from VB/VBA, but Visual Studio Express did a fine job pointing these out to me and debugging the application.
If you feel like using OCX libraries is not your cup of tea or using the SAPGUI Libraries in general is too much of a moving target, take a look at the ERPConnect by Theobald Software GmbH. Normally, I do not endorse 3rd party products but theirs (just one dll to include!) worked for me out of the box and appeared to be a pretty robust implementation which comes with very good documentation.
Hope it helps!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Set sapsHShell = WScript.CreateObject("WScript.Shell")
quotes=chr(34)
sapSHShell.Run quotes & "C:\Program Files\SAP\FrontEnd\SAPgui\saplgpad.exe" & quotes ,2,false
wscript.sleep 10000
'Note: Sap Gui Scripting activex control is called from the SAP Launch pad I believe.
Set SapGui = GetObject("SAPGUI")
Set application = SapGui.GetScriptingEngine
Set connection = application.OpenConnection("Production Name", True)
Set Session = connection.children(0)
session.findById("wnd[0]/usr/txt[1]").text = Login Name
session.findById("wnd[0]/usr/pwd").text = Password
session.findById("wnd[0]").sendVKey 0
This is enough to log in, and take care of an email popup, or 2nd connection popup.
Most everything is exposed.
There are programs that can be used like "SAP Gui Scripting Spy" that displays the names of screen parts, buttons, bars etc... IE: the parts you want to access. Example: I query the The main window titl below. The status bar is ("wnd[0]/sbar").text. hope this helps.
if session.findById("wnd[0]/titl").text="SAP Easy Access" then
else
session.findById("wnd[1]/usr/rad[1]").select
session.findById("wnd[1]/usr/rad[1]").setFocus
session.findById("wnd[1]").sendVKey 0
end if
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I know this is a rather old thread, however hopefully someone can be of assistance.
I am family with VBS, VBA, VB.net, but have never used it for sake of extracting or automating things from and in sap.
As an experiment I was hoping to achieve three automated tasks as a learning curve.
1. At the helpdesk we monitor SAP jobs for being finished and or failing being cancelled at specific times. We then have an excel sheet in which we audit these jobs for failures or completion. Instead of manually going into the SAP GUI, checking each job, marking the excel cell with finished or otherwise. Would there be a way for me to automate this?
So that at a click of a button I could automate logging into sap, checking through sm37 specific job for status, then that returned status being filled in a specific cell in excel.
2. At a specific time of day we email certain employes idoc status 51 errors. We go into WE05, type in the basic type execute, then click on the status 51, click on status list (f7), we get the status details where we can see idoc number, stat, message number, message and we export as a local file, then attach this to an email and send to a number of users.
I know how to automate attachments email etc.. via vba/vbs, however the labourous sap portion is key
3. Be able to get results back in excel through SU01 of usernames, status as locked or unlocked prehaps even unlock or lock without the GUI that would be cool.
These were three 'mini projects' as a learning curve I was hoping to achieve.
Thus far I have not 'googled' upon anything specific of this nature.
I have used SAP for the last 4 years merely as a worker at the helpdesk checking some of these processes, creating or changing jobs, however I have no further SAP experience, still a learner! However I am very family with windows, active directory, programming in VB language, etc...
I have been that SAP can be communicated via "RFC" however I have yet to understand the concept or see an example similar to what I am trying to achieve to fiddle with.
We use multiple SAP systems as we are an affiliate to a company and we have our own SAP system and other SAP systems we connect to using SNC/single sign on.
In a nutshell I would hope to achieve these feats without opening the GUI. For instance the emailing of the status 51 errors, would be wonderful to write a VBS and then put this on our sql server and run the query and emali the resulting spreadsheet xls extract at a specific time and email to a number of people.
All help and advice is very appreciated!
Hi,
I use SAP via full automation using the SAP client, I created an encrypted password text file, then decrypt it upon log in to the client automatically then I start some processes. I process lots of data Via SM37, using SAP back ground processes from most any transaction or report, some from se16 directly, most from sa38 and will use whatever transactions is required that my customer wants data for. I created a process called XUIS that combines VBS,Excel VBA and SAS to parse the extracted data automatically after saving to a text file, then process the data to the end customers requirements. Most of my customer requirments combine multiple reports targeted at supply chain management to form different types of dashboards, metrics or whatever is wanted.
I use a combination of default screen, expected window numbers, changes in title text, default record counts and a bunch of other stuff to adjust to environment changes automatically. IE: errors of not expected results, and variant changes for both program variants and display variants. An example would be that if a program like ze16 was created to filter se16 table views any field additions or changes rebuilds the page, so the record default will show instead of my variants default. Lets say that I created a program variant in se16 for marc or vttk. I would place a record max field on the attribute selection screen, if the default is 50,000 records i would bounce it up to 65,000 records. If someone changes my variant, or there is an update to SAP the default record count will drop back to 50,000. So first I check for the existance of the field, if found I check for the text in the field. if 65000, the assumption is it is still my variant and continue processing. If my target field does not exist, or if the record count is different from 65000, I call a variant rebuild function for the area I am in and redo the variant, save it, then process the filter selections.
Picking up data from sm37 in the form of background Jobs is even easier. One of my processes logs in, goes into sm37, filters on the job name, walks into the spool itself, moves to the details, then saves the results to a text file. once saved the process exits SAP then starts the parsing modules coded in either VBA in excel, or SAS determined by data and record sizes. Then processes the data per user requirments.
If any of this is interesting to you all, I am at cromithius at sbcglobal.net to give me a heads up that you placed a question herre and I will share code, examples and ideas with you. I have been doing this for the past couple of years, so the process is pretty stable.
Thanks. by the way, one of the reasons to use the client to gather data directly instead of Excel via RFC is data format and width from the spool area. I have not found a way to save sm37 (spooled) report data to an external file without the client. part of the file saving code or something like that is held in the client. This is the primary reason I went this route instead of Excel and RFC.
thanks
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Andreas,
Did you already try:
Set connection = application.Children(0)
Maybe that will help.
Regards,
Erkan
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Erkan Kopuz,
I tried to use the code you add to the blog but I got an error
Object does not support this property or method at libe
Set Connection = FunctionCtrl.Children(0)
Could you please help me to solve this issu, I don´t want to receive SAP error, I need to show my own message error
Thanks
SapConnection.client = "160"
SapConnection.user = "sap*"
SapConnection.Password = "brs"
SapConnection.Language = "EN"
SapConnection.HostName = "cpfl0052"
SapConnection.SystemNumber = "20"
If Not IsObject(Application) Then
Set SapGuiAuto = GetObject("SAPGUI")
' Set Application = SapGuiAuto.GetScriptingEngine
End If
If Not IsObject(Connection) Then
Set Connection = FunctionCtrl.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]/mbar/menu[5]/menu[4]").Select
If session.findById("wnd[0]/sbar").Text = "You are not authorized to use Transaction SO99" Then
MsgBox "You are not authorized to use Transaction SO99", vbCritical, "Warning: No authorisation"
End If
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I guess I dont have enough priviliges to test that. Somehow I do get "Connection refused" in my log files. Though, I can create a connection or I can connect to an existing connection. I just tested this code and it worked:
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]/mbar/menu[5]/menu[4]").select
if session.findById("wnd[0]/sbar").text= "You are not authorized to use Transaction SO99" then
msgbox "You are not authorized to use Transaction SO99",vbCritical,"Warning: No authorisation"
end if
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Are you sure that works? I do get "not connected" all the time. BUT if I use the following code, it does work (but still with the gui login):
'Create a function object
Set functionCtrl = CreateObject("SAP.Functions")
'Connect to R/3
Set sapConnection = functionCtrl.Connection
sapConnection.Client = "900"
sapConnection.user = "****" 'Your user id
sapConnection.Language = "EN"
sapConnection.password = "****" ' Your password
SapConnection.HostName = "****"
SapConnection.SystemNumber = "01"
If sapConnection.logon(0, False) Then
MsgBox "No connection to R/3!"
End If
And this is actually similar to your code, right? Or am I making a mistake here?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Im not known with the way you do the login. I use the following:
Set R3 = CreateObject("SAP.Functions")
R3.Connection.System = "denmark"
R3.Connection.client = "100"
R3.Connection.user = "SAP*"
R3.Connection.password = ""
R3.Connection.language = "EN"
If R3.Connection.logon(0, False) <> True Then
But this will start the SAPlogon...im not sure which method you want to use?
I just tried your code, but somehow I cant get it working (even without the lines you have added afterwards)...
Could you give me the right code for the login, so I can try to help you out with that peace of code? We are quite close I guess 😃
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
mhh, thats odd, yours is the same, except that it calls a gui window, mine does not.
Anyway, if you stick this into a .vbs file and just execute it from a command line it should connect fine
(change your logon details of cousre). At least it does for me
Set FunctionCtrl = CreateObject("SAP.Functions")
Set SapConnection = FunctionCtrl.Connection
SapConnection.client = "100"
SapConnection.user = "testuser"
SapConnection.password = "secret"
SapConnection.language = "EN"
SapConnection.HostName = "willibald"
SapConnection.SystemNumber = "00"
If Not SapConnection.Logon(0, True) Then
msgbox("Not Connected")
else
msgbox("Connected")
SapConnection.logoff
End If
Indeed, it is lots of work and you only have to do this once. But somehow it seems like no one did this, because I really looked for days to find any information regarding this issue and I was not able to find this information. And even if I found something, it was not good enough....
Regards,
Erkan
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Andreas,
So what would you like to see? The errors logged into a file?
I found out how to get the messages from the GuiStatusbar and write these into a logfile (or popup with msgbox).
Here an example on how to get the error messages:
if session.findById("wnd[0]/sbar").text= "You are not authorized to use Transaction SO99" then
msgbox "You are not authorized to use Transaction SO99",vbCritical,"Warning: No authorisation"
The problem is you have to do some testing to get the errors you need, so you can fix the code.
I dont have lots of experience in VBS but I do have lots of experience in VBA (almost the same languages tho) and I know how to create a log file into VBA, but somehow I couldnt get it working in VBS (This might be because I do not have the right tools to compile VBS).
Example VBA:
Dim WrongLogFileName
Dim WrongLogtext
If session.findById("wnd[0]/sbar").Text = "You are not authorized to use Transaction SO99" Then
WrongObject = "No Authorisation"
ErrDescription = "You are not authorized to use Transaction SO99"
'for testing purposes
'MsgBox Err.Description & vbNewLine & vbNewLine & vbNewLine & "Error file has been created...", vbCritical, "Error Number" & Err.Number
WrongLogFileName = "C:\ErrorLog.txt"
WrongLogtext = Date & " om " & Time & " - " & vbCrLf & " Object : " & WrongObject & vbCrLf & " Error number: " & Err.Number & vbCrLf & " Error description: " & vbCrLf & " " & ErrDescription & vbCrLf
Open WrongLogFileName For Append As #1
Print #1, WrongLogtext
Close #1
end if
Hope this helps you a bit
Regards,
Erkan
Edited by: Erkan Kopuz on Feb 19, 2008 11:02 AM
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hum,
I tried that, I am starting to wonder if that actually works with VBScript.
The error I am getting is
Object doesn't support this property or method:'SapConnection.findById
Code:
Set FunctionCtrl = CreateObject("SAP.Functions")
Set SapConnection = FunctionCtrl.Connection
SapConnection.client = "<CLNT>"
SapConnection.user = "<WRONG_USER>" '<---------- !
SapConnection.password = "<PASS>"
SapConnection.language = "<LANG>"
SapConnection.HostName = "<HOST>"
SapConnection.SystemNumber = "<NR>"
If Not SapConnection.Logon(0, True) Then
if SapConnection.findById("wnd[0]/sbar").text= "Name or password is incorrect (repeat logon)" then
msgbox "Name or password is incorrect (repeat logon)",vbCritical,"Warning: No authorisation"
end if
else
<Excellent, connected, do some useful stuff>
SapConnection.logoff
End If
Jerry Borst, how would you like to use that in VBS if you would like to show a messagebox of the warnings that is shown in the GuiStatusbar of SAPGui? I guess not like that...
Andreas Appelbaum,
I know what you mean. I have an Excel file which can download tables into a spreadsheet without opening SAPGui. The beginning of this code is actually the same as you posted in your last reply. But I do get error messages when something is wrong. For example if I enter a wrong password, then a messagebox will popup with the following message: "Name or password is incorrent. Please re-enter". So seems like it does have something like an errorhandler.
Now, Im also looking for a way to have a messagebox of the messages who are shown by the GuiStatusbar...I hope I will find the answers here as I already searched for this via google but wasnt able to find anything about this subject (except for the Gui scripting manual).
Edited by: Erkan Kopuz on Feb 19, 2008 9:26 AM
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Have you tried...
if session.findById("wnd[0]/sbar").text=
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello,
thanks for all your thoughts, highly appriciated!
I still dont undersand how to put this into my code though.
BTW - my scripts work fine and well, retrieving performance data out of ABAP. The idea of this execrcise is to write a proper log file/alert on why the connection did not work.
Set FunctionCtrl = CreateObject("SAP.Functions")
Set SapConnection = FunctionCtrl.Connection
SapConnection.client = "<CLNT>"
SapConnection.user = "<USER>"
SapConnection.password = "<PASS>"
SapConnection.language = "<LANG>"
SapConnection.HostName = "<HOST>"
SapConnection.SystemNumber = "<NR>"
If Not SapConnection.Logon(0, True) Then
<Somehow get what the actual error was>
else
<Excellent, connected, do some useful stuff>
SapConnection.logoff
End If
I am not entirely sure but the examles given above all show a GUI screen, is that right?
Thanks again,
Andi
sorry for the late answer, i guess you should include the SAP Scripting Control (sapfewse.ocx) in Visual Basic
Object = GuiStatusbar
btw I also seen code like:
SAPGuiSession("Session").SAPGuiWindow("Create Standard").
SAPGuiStatusBar("StatusBar").Output
I didnt test anything, im just trying to help you 😃
hope this helps
Good luck
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.