on 07-08-2010 9:24 AM
in vbs script
if multiple sap session is open i want to give option to user for selecting the right sap session for executing the script operation.
below is script where user will enter the customer code and other details in XD02
then execute the script and the script will execute
but here the first child(0) will be select, here i want option so that system will ask select the window where you want to execute the script once i select it will execute the below script, on that session.
ex.
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[1]").sendVKey 0
session.findById("wnd[0]/tbar[1]/btn[48]").press
session.findById("wnd[0]/usr/tabsCIN_CUSTOMER/tabpCIN_CUSTOMER_FC1/ssubCIN_CUSTOMER_SCA:SAPLJ1I_MASTER:0201/txtJ_1IMOCUST-J_1IEXCD").text = "NA"
session.findById("wnd[0]/usr/tabsCIN_CUSTOMER/tabpCIN_CUSTOMER_FC1/ssubCIN_CUSTOMER_SCA:SAPLJ1I_MASTER:0201/txtJ_1IMOCUST-J_1IEXCD").caretPosition = 2
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/tbar[0]/btn[3]").press
session.findById("wnd[0]/tbar[0]/btn[11]").press
Hi samir,
If I have understood correctly, it will need the following:
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
Modus = int(inputbox("Please enter a session:", "SAP - Session", 1 ))
if Modus = 0 then wscript.quit
for session_number = 0 to connection.children.count - 1
Set session = connection.Children(int(session_number))
if session.info.sessionnumber = Modus then exit for
next
if Modus > session.info.sessionnumber then wscript.quit
. . .
Regards,
ScriptMan
Edited by: ScriptMan on Jul 9, 2010 7:41 AM
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
hi script man
Thanks for response
but here my requirement is little different
suppose on your pc there are multiple sap session is open eg. xd03, va01, vf01 or two same transaction xd02,xd02
when i run script file it will ask me "please select the application(session) where you want to execute script"
i will simply activate the windows of SAP session from task bar where script need to execute and then i will click on message of wsript OK then it should activate last selected sap session and then should run script over there.
here the problem is i want to find the session no./children (N) of last activated sap session before click on execute script.
the N need to be find. where N is no of last activated session before clicking on message generated by vbs script.
i know it will little difficult but there will be some way..and i know you help me out...
i want to design it for end user those don't know about ABC of sap gui scirpt or VBS so they will not able to trace which no. should they enter for selecting right session? but they can select that window from task bar and then click execute .
i will be thanks for the same.
Hi samir,
O.K. let's see what we can do. The problem is that the called VB script should not get the focus. This can be realized in different ways. It depends on how it is run.
1. Example for run from Windows Explorer
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
msgbox "Please select a session within the next 5 seconds"
wscript.sleep 5000
set session = application.ActiveSession
. . .
2. Example for run from Link to VB-Skript on the Desktop
The link should be run in minimized mode and it must a hot key be defined.
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
set session = application.ActiveSession
. . .
In this case, a session should be activated first. Then can the VB-Skript be running with hot key.
Regards,
ScriptMan
here can we have this...option
we will execute script it will wait for certain key combination to be released by user
once user activate the sap session and press those key combination so the script will start executing remaining line on active session.
i think it can be look like event driven program. but i don't know how to capture the key-press event on windows os (not for particular session or application like excel but any where in windows system) using vb script.
great if we able to find out than we can have different action for different key combination and our script will be ruining in background and we can trigger action as per key combination. no need to create shortcut in sap gui using guixt nor executing different files form desktop for different actions.
do you have any idea so that we can achieve this.
hi script man
you have not get me..
here i am asking for keypress event not for creating short cut for script.
i want something like
window.onkeypress(s_key)
{
if s_key = ctraltr then
session = active.application
" REMAINING CODE GOES HERE
end if
' SECOND OPTION
if s_key = ctraltC then
session = active.application
" REMAINING CODE GOES HERE
end if
}
'remaining code here
so there is no way to capture the key press.. in script..?
is it then let me know...
There can be a way...
if you can access Api's and do a general Keyboard-Hook - but that would be shooting Pigeons with a machine Gun...
it cant be done easy
If you want to do the "Hard" way you can google für Keyboard - Hook
or use this link:
http://www.activevb.de/tutorials/tut_subcls/subcls.html
its in German so i dont know if you can handle it but you can try<
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.