cancel
Showing results for 
Search instead for 
Did you mean: 

Run 1 script in each sessions

05-07-2017 9:33 AM
747 views 2 comments
0 Likes
SAP Managed Tags
Subscribe

Hello,

I want to run 1 script for each sessions open in my SAP GUI.
The first script is functionally, but the second wait the first script before to start.
I use multi-threading in C# to run those 2 script in parallel but it doesn't good.

Is it possible to run multiple script in parallel ? If yes, how to do that ?

0 Likes

Accepted Solutions (0)

Answers (1)

Answers (1)

Stefan-Schnell
Active Contributor
0 Likes

Hello Corentin,

yes, it is possible. I tried it with PowerShell and the Job commands. At first I create a script which calls TAC SE16 and opens table TADIR ten times.

#-Begin-----------------------------------------------------------------

  #-Parameters----------------------------------------------------------
    Param($SessionNo)

  #-Includes------------------------------------------------------------
    ."C:\Dummy\COM.ps1"

  #-Main----------------------------------------------------------------
    $SapGuiAuto = Get-Object "SAPGUI"
    If ($SapGuiAuto -isnot [__ComObject]) {
      Exit
    }

    $application = Invoke-Method $SapGuiAuto "GetScriptingEngine"
    If ($application -isnot [__ComObject]) {
      Free-Object $SapGuiAuto
      Exit
    }

    $connection = Get-Property $application "Children"
    If ($connection -eq $Null) {
      Free-Object $SapGuiAuto
      Exit
    }
    If ($application.Children().Count() -gt 1) {
      $connection = $connection[0]
    }

    $session = Get-Property $connection "Children"
    If ($session -eq $Null) {
      Free-Object $SapGuiAuto
      Exit
    }
    If ($connection.Children().Count() -gt 1) {
      $session = $session[$SessionNo]
    }

  For ($i = 1; $i -le 10; $i++) {
    $ID = Invoke-Method $session "findById" @("wnd[0]/tbar[0]/okcd")
    Set-Property $ID "text" @("/nse16")
    $ID = Invoke-Method $session "findById" @("wnd[0]/tbar[0]/btn[0]")
    Invoke-Method $ID "press"
    Start-Sleep -s 1
    $ID = Invoke-Method $session "findById" @("wnd[0]/usr/ctxtDATABROWSE-TABLENAME")
    Set-Property $ID "text" @("TADIR")
    $ID = Invoke-Method $session "findById" @("wnd[0]/tbar[1]/btn[7]")
    Invoke-Method $ID "press"
    Start-Sleep -s 1
    $ID = Invoke-Method $session "findById" @("wnd[0]/tbar[1]/btn[8]")
    Invoke-Method $ID "press"
    $ID = Invoke-Method $session "findById" @("wnd[0]/tbar[0]/btn[3]")
    Invoke-Method $ID "press"
    Start-Sleep -s 1
    $ID = Invoke-Method $session "findById" @("wnd[0]/tbar[0]/btn[3]")
    Invoke-Method $ID "press"
    $ID = Invoke-Method $session "findById" @("wnd[0]/tbar[0]/btn[3]")
    Invoke-Method $ID "press"
  }

#-End-------------------------------------------------------------------

Then I started this script via start-job command two times and the sessions works peaceful side by side parallel.

#-Begin-----------------------------------------------------------------

start-job -Name j1 -FilePath C:\Dummy\test.ps1 -ArgumentList 0
start-job -Name j2 -FilePath C:\Dummy\test.ps1 -ArgumentList 1

wait-job -name j1
wait-job -name j2

receive-job -name j1
receive-job -name j2

#-End-------------------------------------------------------------------

I transfer the parameter session number in the AgrumentList parameter, in my case session 0 and 1 from connection 0.

I am no C# programmer, so I can't say how to do that in C# language.

Cheers
Stefan

kiran_k8
Active Contributor

Stefan,

"and the sessions works peaceful side by side"- I liked that statement 🙂

K.Kiran.