cmshell for sap - connmove gmbhconnmove.eu/.../uploads/2014/02/cmshell_for_sap-guiscripting.pdf ·...
TRANSCRIPT
Seite 1 von 15
cmShell for SAP SAP GUI Scripting
CommandLets for SAP GUIScripting
connmove GmbH Version: 0.7
Seite 2 von 15
Inhalt
Requirements ...................................................................................................................................... 3
Record a script .................................................................................................................................... 4
Start at SAP Easy Access menu ..................................................................................................... 4
Choose script path ........................................................................................................................... 4
Start recording ................................................................................................................................. 5
Call transaction AL08 ....................................................................................................................... 5
Stop recording ................................................................................................................................. 6
Connect to the SAP GUI ..................................................................................................................... 7
Open a SAP GUI session ................................................................................................................ 7
Run the script ...................................................................................................................................... 7
Stop the SAP GUI connecction ........................................................................................................... 8
Access the result value ....................................................................................................................... 8
Statusbar message ............................................................................................................................. 9
GUI elements .................................................................................................................................... 10
64bit PowerShell ............................................................................................................................... 11
GUI GridView .................................................................................................................................... 11
Usage Step by Step .......................................................................................................................... 13
Quellen .............................................................................................................................................. 15
SAP GUI Scripting API for the Windows and Java Platforms: ................................................... 15
SAP note 1441550 SAP GUI Scripting: Beispielanwendungen: ................................................ 15
SAP GUI Scripting Security Guide: ............................................................................................ 15
SAP GUI Scripting documentation: ............................................................................................ 15
The SAP Control Framework: .................................................................................................... 15
Seite 3 von 15
Requirements
- SAP GUI must be installed on the client system.
- SAP GUI Scripting must be enabled on the application server by setting the
sapgui/user_scripting parameter.
- SAP GUI Scripting must be enabled on the client system in the Option dialog of the SAP GUI.
Seite 4 von 15
Record a script
Start at SAP Easy Access menu
Choose script path
Seite 5 von 15
Start recording
Call transaction AL08
Seite 6 von 15
Stop recording
Seite 7 von 15
Connect to the SAP GUI use 32bit PowerShell
Open a SAP GUI session
$sapGUIConnection = Get-CmSapGuiConnect -UserName admin -Password ****** -Host CMD002 -Hide $false -MultiLogon $true
Optional parameter
Hide: Do not show the SAP GUI (default true) MultiLogon: Allow multiple logons to the production system using the same user (default
false)
Run the script $result = Invoke-CmSapGuiScripting -FileName c:\tmp\sapgui\al08.vbs $sapGUIConnection –StatusbarOnly $true
Optional parameter:
StatusbarOnly: Return only the message displayed in the status bar (default false)
Seite 8 von 15
Stop the SAP GUI connecction You may execute more scripts. When finished you have to call the Close-CmSapGuiConnect method:
Close-CmSapGuiConnect $sapGUIConnection
Access the result value The commandlet returns a List<String[]> object. The elements of the List<String[]> consists of a pair of strings ( GUI element type, value).
PS > $result.GetType() IsPublic IsSerial Name BaseType -------- -------- ---- -------- True True Object[] System.Array
Seite 9 von 15
Statusbar message The first element contains the status bar message:
PS> $result[0] GuiStatusbar Selection restricted to 200 hits
The statusbar message is empty at the AL08 example:
Seite 10 von 15
GUI elements You can run several operations on the list, such as
PS > $result.Count 53 PS > $result.Get(10) GuiLabel Interactive Users
Seite 11 von 15
64bit PowerShell You may use the cmdlet from a 64bit PowerShell by calling the start-job commandlet:
# Set the input parameter. $argumentList = $UserName, $Password, $HostName, $Client, $scriptPath # Run the SAP GUI scripting command lets in a 32bit environment. $rfcCheckResult = start-job { param($UserName, $Password, $HostName, $Client, $scriptPath) add-pssnapin CmCmdlets; $sapGUIConnection = Get-CmSapGuiConnect -UserName $UserName -Password $Password -Host $HostName -Client $Client -Hide $false -MultiLogon $true; Invoke-CmSapGuiScripting -FileName $scriptPath $sapGUIConnection; $null = Close-CmSapGuiConnect $sapGUIConnection } -RunAs32 -ArgumentList $argumentList | wait-job | Receive-Job
GUI GridView On some dypros the data is displayed in a GridView. In this case the elements of the List<String[]> consists of a pair of strings ( SAP table column name, value).
PS C:\Windows\system32> $result.Get(1) BNAME ADMIN PS C:\Windows\system32> $result.Get(2) NAME_TEXT Administrator Admin PS C:\Windows\system32> $result.Get(3) CLASS SUPER PS C:\Windows\system32> $result.Get(4) ACCNT PS C:\Windows\system32> $result.Get(5) LOCKICON PS C:\Windows\system32> $result.Get(6) LOCKREASON PS C:\Windows\system32> $result.Get(7) GLTGV PS C:\Windows\system32> $result.Get(8) GLTGB PS C:\Windows\system32> $result.Get(9) USTYP A Dialog PS C:\Windows\system32> $result.Get(10) REFUSER
Seite 12 von 15
Seite 13 von 15
Usage Step by Step 1. Open a SAP GUI session
$con = Get-CmSapGuiConnect -UserName admin -Password 1Password! -
Host ERP -Hide $false -MultiLogon $true
Optional parameter
Hide: Do not show the SAP GUI (default true)
MultiLogon: Allow multiple logons to the production system using the same user (default
false)
2. Execute a SAP script
$result = Invoke-CmSapGuiScripting -FileName c:\tmp\sapgui\script1.vbs $con -
StatusbarOnly $true
Optional parameter
StatusbarOnly: Return only the message from the status bar (default false)
3. The command returns a List<String[]> object with the first element containing the
status bar message:
PS> $result[0]
GuiStatusbar
Selection restricted to 200 hits
4. All elements of the List<String[]> consists of a pair of strings ( GUI element type,
value).
PS > $result[22]
GuiLabel
ABAP_ASSERT
PS > $result[22][0]
GuiLabel
PS > $result[22][1]
ABAP_ASSERT
5. You can run several operations on the list, such as
PS > $result.Count
1003
PS > $result.Get(0)
GuiStatusbar
Selection restricted to 200 hits
PS > $result.GetType()
IsPublic IsSerial Name BaseType
Seite 14 von 15
-------- -------- ---- --------
True True Object[] System.Array
6. You may execute more scripts. When finished you have to call the Close-
CmSapGuiConnect method:
PS > Close-CmSapGuiConnect $con
Seite 15 von 15
Quellen
SAP GUI Scripting API for the Windows and Java Platforms:
http://www.synactive.com/download/sap%20gui%20scripting/sap%20gui%20scripting%20api.pdf
SAP note 1441550 SAP GUI Scripting: Beispielanwendungen:
https://websmp130.sap-ag.de/sap%28bD1kZSZjPTAwMQ==%29/bc/bsp/spn/sapnotes/index2.htm?numm=1441550
SAP GUI Scripting Security Guide:
http://www.synactive.com/download/sap%20gui%20scripting/sap%20gui%20scripting%20security%20settings.pdf
SAP GUI Scripting documentation:
http://service.sap.com/sapgui
The SAP Control Framework:
http://help.sap.com/saphelp_46c/helpdata/en/2a/755b94ca5911d299af5c9604c10e27/frameset.htm