on 05-14-2007 2:18 PM
Hi,
is it possible to use multiple session with VB or not?
Because every time i record with the standard or the extra reorder the opening of an session, this works fine, but then it will open the transaction in the first session not in the new one.
How can i tell him to use the new session.
Yes, it is possible to run multiple GUI scripting sessions with VB.
Your first session is defined with
Set session = connection.Children(0)
Additional sessions will need to be defined after they are active.
Example: After the session.createSession line, insert a short pause in your code to allow time for SAP, then
Set session1 = connection.Children(0 + 1) or
Set session1 = connection.Children(1)
and you will need to change the subsequent code in your recorded script from session.findById... to session1.findById...
Cas
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Sessions are child objects of the connection object. You would need to iterate through the collection to find all of the open sessions and attach to the one you want. In the 7.01 API you can get those by either using the Connection.Children property or the Connection.Session property. The Session property was a recent addition - use Children for older scripting APIs.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you for your answer!
I did it so
*&---------------------------------------------------------------------*
*& Report ZTEST11
*&---------------------------------------------------------------------*
*& SAP GUI Scripting from ABAP
*&---------------------------------------------------------------------*
REPORT ztest11.
* Make and run script from the ABAP program
DATA:
BEGIN OF data_tab OCCURS 0,
line(200) TYPE C,
END OF data_tab,
line LIKE data_tab-line,
text TYPE STRING,
sapworkdir TYPE STRING,
filepath TYPE STRING,
filelength TYPE I.
PERFORM execute_script.
* Write a vb-script line
FORM addline USING line.
CLEAR data_tab-line.
data_tab-line = line.
APPEND data_tab.
ENDFORM. " addline
* Form and execute vb-script
FORM execute_script.
REFRESH data_tab.
* System Id (for example "DEV")
CONCATENATE 'SystemName = "' sy-sysid '"' INTO line.
PERFORM addline USING line.
* Mandant (for example "150")
CONCATENATE 'Client = "' sy-mandt '"' INTO line.
PERFORM addline USING line.
* Number of Mode (on StatusBar)
text = sy-modno + 1.
CONCATENATE 'SessionNumber =' text INTO line SEPARATED BY space.
PERFORM addline USING line.
* Get reference to SAP GUI application
PERFORM addline USING 'Set SapGuiAuto = GetObject("SAPGUI")'.
PERFORM addline USING 'Set application = SapGuiAuto.GetScriptingEngine'.
PERFORM addline USING ''.
* Search the current session and start our vb-script
PERFORM addline USING 'Do'.
PERFORM addline USING ' For Each connection in application.children'.
PERFORM addline USING ' For Each session in connection.children'.
PERFORM addline USING ' If session.Info.SystemName = SystemName And session.Info.Client = Client And session.Info.SessionNumber = SessionNumber Then'.
PERFORM addline USING ' Exit Do '' Found'.
PERFORM addline USING ' End if'.
PERFORM addline USING ' Next'.
PERFORM addline USING ' Next'.
PERFORM addline USING ' Exit Do '' Not Found'.
PERFORM addline USING 'Loop'.
PERFORM addline USING ''.
PERFORM addline USING ' If IsObject(session) then'.
PERFORM addline USING ' If IsObject(WScript) Then'.
PERFORM addline USING ' WScript.ConnectObject session, "on"'.
PERFORM addline USING ' WScript.ConnectObject application, "on"'.
PERFORM addline USING ' RunScript'.
PERFORM addline USING ' End If'.
PERFORM addline USING ' Else'.
PERFORM addline USING ' MsgBox("Session " & SystemName & "(" & CStr(SessionNumber) & ") " & Client & " - not found.")'.
PERFORM addline USING ' End If'.
PERFORM addline USING ''.
* Our useful vb-script (for example, start transaction BIBS)
PERFORM addline USING 'Sub RunScript'.
PERFORM addline USING ' session.findById("wnd[0]").resizeWorkingPane 177,37,false'.
PERFORM addline USING ' session.findById("wnd[0]/tbar[0]/okcd").text = "/nbibs"'.
PERFORM addline USING ' session.findById("wnd[0]").sendVKey 0'.
PERFORM addline USING ' MsgBox ("Hello, SAP! :)")'.
PERFORM addline USING 'End Sub'.
* Get path to download
CALL METHOD cl_gui_frontend_services=>get_sapgui_workdir
CHANGING
sapworkdir = sapworkdir.
* The file to download
CONCATENATE sapworkdir '\script.vbs' INTO filepath.
* Write vb-script into the file in the local PC
CALL METHOD cl_gui_frontend_services=>gui_download
EXPORTING
filename = filepath
IMPORTING
filelength = filelength
CHANGING
data_tab = data_tab[].
* Execute vb-script
CALL METHOD cl_gui_frontend_services=>execute
EXPORTING
document = filepath.
ENDFORM. " execute_script
Hi Gurus,
I'm newbie with SAP and VbScript but i have created some vbscripts.
They works fine !
But I dont know how to identify the sessions SAP
Do you know ?
Daniel.
Ps : xcuse my poor english !
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Let me know whether you are using VB or VB SCripting. What kindof program are you using ? pls provide these information.
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.