on 11-05-2012 11:54 AM
Hi all,
I am quite new to the sap automatization scene but have accomplished quite alot in the last few months due to this forum
However, For my last need i cannot seem to find a solution. That is why i am going to post my first topic here.
What i want to accomplish:
I am using a single sign on system so i do not need to give any user name information. However, i have different systems in my system.
When i use my macros it will log into the one that is open.
Now when i have the need to log into a different system (Defined in the saplogon ofcourse) by Create a new session.
Now i only need to give the order to pick my desired system, but have no clue how.
The code i use for the new session:
[code]
Session_number_max = 6 'MAx
ReDim session_number_(Session_number_max)
On Error GoTo NeedCRM
Set SapGuiAuto = GetObject("SAPGUI")
Set sapp = SapGuiAuto.GetScriptingEngine
On Error GoTo NeedCRM
Set Connection = sapp.Children(0)
Set session = Connection.Children(0)
'------------------------------------------- Lookup -------------------------------------------------------------
session_number_all = Connection.Children.Count - 1
For i = 1 To Session_number_max
session_number_(i) = 0
Next
For session_number = 0 To session_number_all
Set session = Connection.Children(Int(session_number))
session_number_(session.info.sessionnumber) = session.info.sessionnumber
Next
If session_number_all < Session_number_max - 1 Then
session.createsession
Do
waitTill = Now() + TimeValue("00:00:01")
While Now() < waitTill
DoEvents
Wend
If Connection.Children.Count - session_number_all >= 2 Then Exit Do
Loop
On Error Resume Next
Error_number = 1
For session_number = 0 To session_number_all + 1
Err.Clear
Set session = Connection.Children(Int(session_number))
If Err.Number > 0 Or Err.Number < 0 Then Exit For
If session_number_(session.info.sessionnumber) = 0 Then
Error_number = 0
Exit For
End If
'session.findById("wnd[0]").iconify 'So you can send another SAP session in the task bar.
Next
On Error GoTo 0
Else
MsgBox "New session is not possible."
End If
'------------------------------------------- new session connect -------------------------------------------------------------
If Error_number = 0 Then
With session
[/code]
Hopefully someone could help me connect to my defined system,
Thanks alot
Robert.
Oke, The solution was quite easy to open a new window with the right system, however it is asking me for logins which i do not have, so i think i might me on the wrong way?
If Not IsObject(SapGuiApp) Then
Set SapGuiApp = CreateObject("Sapgui.ScriptingCtrl.1")
End If
If Not IsObject(Connection) Then
Set Connection = SapGuiApp.OpenConnection("system", True)
End If
If Not IsObject(Session) Then
Set Session = Connection.Children(0)
End If
Edit---
Oke, so i think the problem is quite bigger since i cannot create shortcuts on my desktop to the desired system witouth being asked for login information.
Investigating further though.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Robert,
welcome in the forum. The code is found with very well known. For the above problem, you can try the following:
for connection_number = 0 to sapp.children.count - 1
Set connection = sapp.Children(int(connection_number))
Set session = connection.Children(0)
if session.info.systemname = "XYZ" then exit for
next
msgbox session.info.systemname
Regards,
ScriptMan
Hi Mona Lisa,
a really beautiful name - I would not be able to choose better.
I know up to now 2 official methods:
1. a visible method
If Not IsObject(SAPguiApp) Then
Set SAPguiApp = CreateObject("Sapgui.ScriptingCtrl.1")
End If
If Not IsObject(Connection) Then
Set Connection = SAPguiApp.OpenConnection("mySYSTEMNAME", True)
End If
If Not IsObject(Session) Then
Set Session = Connection.Children(0)
End If
Session.findById("wnd[0]/usr/txtRSYST-MANDT").Text = "myMANDANT"
Session.findById("wnd[0]/usr/txtRSYST-BNAME").Text = "myNAME"
Session.findById("wnd[0]/usr/pwdRSYST-BCODE").Text = "myPW"
Session.findById("wnd[0]/usr/txtRSYST-LANGU").Text = "EN"
Session.findById("wnd[0]").sendVKey 0
2. a no visible method
Set sap = CreateObject("SAP.Functions")
Set conn = sap.Connection
conn.System = "mySYSTEMNAME"
conn.client = "myMANDANT"
conn.user = "myNAME"
conn.Password = "myPW"
conn.Language = "EN"
If conn.logon(0, True) <> True Then
msgbox "Login to the SAP system is not possible.", vbOKOnly, "comment"
else
'myCode
end if
But both have something in common: SAP session is closed when the programs are finished.
Regards,
ScriptMan
Thanks a bunch for the code .
I am using the below coding
Sub sVBScriptSAP()
On Error Resume Next
If Not IsObject(SAP_applic) Then
Set SapGuiAuto = GetObject("SAPGUI")
Set SAP_applic = SapGuiAuto.GetScriptingEngine
End If
er = Err.Number
On Error GoTo 0
If er <> 0 Then
er = 0
On Error Resume Next
Call Shell("C:\Program Files\SAP6\SAPgui\saplogon.exe", vbMinimizedFocus)
Call Shell("C:\Program Files\SAP640\SapGui\saplogon.exe", vbMinimizedFocus)
On Error GoTo 0
er = 0
On Error Resume Next
If Not IsObject(SAP_applic) Then
Set SapGuiAuto = GetObject("SAPGUI") 'Setting
Set SAP_applic = SapGuiAuto.GetScriptingEngine
End If
er = Err.Number
On Error GoTo 0
If er <> 0 Then
tmp = MsgBox("SAP Logon not installed on your system" & vbCrLf & _
"Please install it using eSupport!", vbInformation)
End
End If
End If
Set Connection = SAP_applic.openconnection(SAPBox)
Set Session = Connection.Children(0)
End Sub
When i run the macro , i get error as "error description not available" can u tell me why this error is coming . where i am going wrong .
thanks a lot once again
Hello ScriptMan,
Thanks for replying .
I have opened a new thread . Here it is http://scn.sap.com/thread/3270803 .
Please take a look,
Monalisa
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.