on 05-17-2013 7:09 AM
Hi everyone,
with the code i was able to open a connection to SAP .
Set sap = CreateObject("SapAutoGui.Event")
host = "test12"
sapNr = "90"
mandant = "800"
user =" test1"
Password = "pass"
bOK = sap.Connect(host , sapNr ,SapGuiActiveX Or SapGuiFront Or SapGuiFullMenu)
OKCheck bOK, "Error in opening connection"
iCtrl = sap.FindByField("RSYST-MANDT", 0, SapEdit)
bOK = sap.SetControlValue(iCtrl, mandant)
OKCheck bOK, "Error in setting text value"
iCtrl = sap.FindByField("RSYST-BNAME", 0, SapEdit)
bOK = sap.SetControlValue(iCtrl, user )
OKCheck bOK, "Error in setting text value"
iCtrl = sap.FindByField("RSYST-BCODE", 0, SapPassword)
bOK = sap.SetControlValue(iCtrl, Password)
OKCheck bOK, "Error in setting text value"
bOK = sap.SetCursorByControl(iCtrl)
OKCheck bOK, "Error in setting cursor position"
bOK = sap.SendEvent
OKCheck bOK, "Error in sending default key"
but since SNC is active, i can't open sap
how do I make a connection to SAP when SNC = true
Can anyone help me?
Thanks,
saad
Hello Saad,
'--------------------------Start Excel VBA Sub-----------------------------
Sub SAP_OpenSessionFromLogon()
Dim SapGui
Dim Applic
Dim connection
Dim session
Shell ("C:\Program Files\SAP\FrontEnd\SAPgui\saplogon.exe")
Set SapGui = GetObject("SAPGUI")
Rem Create the GuiApplication object
Set Applic = SapGui.GetScriptingEngine
Rem Open a connection
Set connection = Applic.OpenConnection("QE1 - ERP QA ECC 6.0", True) '<=== here you need to fillin your connection description
Set session = connection.Children(0)
session.findById("wnd[0]").maximize
session.findById("wnd[0]/usr/txtRSYST-MANDT").Text = "800"
session.findById("wnd[0]/usr/txtRSYST-BNAME").Text = "Test1"
session.findById("wnd[0]").sendVKey 0
Rem Do something: Either fill out the login screen
Rem or in case of Single-Sign-On start a transaction.
session.SendCommand ("/nbibs")
MsgBox "Waiting..."
Rem Shutdown the connection
Set session = Nothing
connection.CloseSession ("ses[0]")
Set connection = Nothing
Set sap = Nothing
MsgBox "Done"
End Sub
'--------------------------End of Excel VBA Sub----------------------------
Just fillin the description from your system in row where 'Set connection' is defined.
If you have any questions let me know. Br, Holger
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello.
Check for SAPGuiScripting helpfile in any searchmachine and download.
When you have only one client (client = "800") on this system this lines are not required.
Or you can check if they´re changeable
session.findById("wnd[0]").maximize
If session.findById("wnd[0]/usr/txtRSYST-MANDT").Changeable = True Then
session.findById("wnd[0]/usr/txtRSYST-MANDT").Text = "800"
session.findById("wnd[0]/usr/txtRSYST-BNAME").Text = "Test1"
session.findById("wnd[0]").sendVKey 0
End If
Br, Holger
Hello Javier,
In Holger's codes, you can replace the set connection = Applic.OpenConnection("your.connection.name", True) to set connection = Applic.OpenConnectionByConnectionString("your.server.name.here", True).
A more proper way to use the OpenConnectionByConnectionString method is to use the prefixes /H/ for 'Host', /S/ for 'Service (port)', /M/ for 'Message Server' where applicable, but I found that discarding the prefixes still works.
Thanks,
Sayuti
Hello Sayuti,
Tks for your prompt answer.
I tried with Server Name, but it is opening a SAP section for UserID and Password. in our Co we have dual mode (User/Password) or SNC (UserID Only), for the same Server Name.
I'll use description name (picked by SAPGUI client) and logon using that parameters.
Thank you for your help.-
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.