Jump to content

Recommended Posts

Posted (edited)

Hello community,

the SAP GUI for Windows offers an SAP GUI Scripting recorder to record manual activities. Press Alt+F12 to open the Local Layout menu and choose Script recording and playback item to open the recorder. The activities are stored in VBScript language, but it is very easy to use the recording results with AutoIt. It is only necessary to set a $ sign before the session variable and to set a stub in front of the recording results.

Here an example for a login:

;-Begin-----------------------------------------------------------------

;-Variables-----------------------------------------------------------

Dim $SAPROT, $SapGuiAuto, $application, $connection, $session

$SAPROT = ObjCreate("SapROTWr.SAPROTWrapper")

If Not IsObj($SAPROT) Then

Exit

EndIf

$SapGuiAuto = $SAPROT.GetROTEntry("SAPGUI")

If Not IsObj($SapGuiAuto) Then

Exit

EndIf

$application = $SapGuiAuto.GetScriptingEngine()

If Not IsObj($application) Then

Exit

EndIf

$connection = $application.Children(0)

If Not IsObj($connection) Then

Exit

EndIf

$session = $connection.Children(0)

If Not IsObj($session) Then

Exit

EndIf

;-SAP GUI Scripting from recorder starts here---------------------------

$session.findById("wnd[0]/usr/txtRSYST-MANDT").text = "099"

$session.findById("wnd[0]/usr/txtRSYST-BNAME").text = "Hugo"

$session.findById("wnd[0]/usr/pwdRSYST-BCODE").text = "Bambi"

$session.findById("wnd[0]/usr/txtRSYST-LANGU").text = "DE"

$session.findById("wnd[0]/tbar[0]/btn[0]").press()

;-End-------------------------------------------------------------------

The $session.findById code is direct from the SAP GUI Scripting recorder. With a search and replace it is very easy to set a $ in front of session.

You find the equivalent posting in the SAP Community Network here.

Cheers

Stefan

Edited by StSchnell
  • 7 months later...
Posted

Hi   Appreciate your post and I have a question that I can't seem to find with google.  Tried various ways to accomplish a simple goal of seleting a Tab in SAP trnasaction IW32.  See Code.  I can often jump from Tab Additional Data to HeaderDate and then to Component Tab but after that everything fails. Do you have Hint that you can give?    Below is a simple form with the Tabs I would like to be able to select.  After clicking the button you have 3 seconds to select the SAP module.  It then connects to SAP and tries to Select the desired Tab. 

Thanks for any HELP  :)

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

#region
Global $sapGUI, $sapAPP, $sapConnection, $sapSession
#endregion


#Region ### START Koda GUI section ### Form=E:ProgramsAutoIt3koda_1.7.3.0FormsSAP_Test.kxf
$frmSap_Test = GUICreate("SAP", 158, 182, 487, 200)
$cmdHeader = GUICtrlCreateButton("Header Data", 16, 8, 121, 25)
$cmdOperation = GUICtrlCreateButton("Operation", 16, 40, 121, 25)
$cmdComponents = GUICtrlCreateButton("Components", 16, 72, 121, 25)
$cmdPartner = GUICtrlCreateButton("Partner", 16, 104, 121, 25)
$cmdLocation = GUICtrlCreateButton("Location", 16, 140, 121, 25)
GUISetState(@SW_SHOW)
WinSetOnTop($frmSap_Test, "", 1)
ConsoleWrite(@CRLF)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $cmdHeader
            Call(_HeaderClick())
        Case $cmdOperation
            Call(_OperationClick())
        Case $cmdComponents
            Call(_ComponentsClick())
        Case $cmdPartner
            Call(_PartnerClick())
        Case $cmdLocation
            Call(_LocationClick())

    EndSwitch
WEnd

Func _ConnectToSAP()
    
    Sleep(3000)
    $sapGUI = ObjGet("SAPGUI")
    $sapAPP = $sapGUI.GetScriptingEngine
    $sapConnection = $sapAPP.Children(0)
    $sapSession = $sapAPP.ActiveSession
EndFunc


Func _HeaderClick()
    Call(_ConnectToSAP())
    ConsoleWrite("Click Header Tab" & @CRLF)
    $sapSession.findById("wnd[0]/usr/subSUB_ALL:SAPLCOIH:3001/ssubSUB_LEVEL:SAPLCOIH:1100/tabsTS_1100/tabpIHKZ").Select
EndFunc


Func _OperationClick()
    Call(_ConnectToSAP())    
    ConsoleWrite("Click Operation Tab" & @CRLF)
    $sapSession.findById("wnd[0]/usr/subSUB_ALL:SAPLCOIH:3001/ssubSUB_LEVEL:SAPLCOIH:1100/tabsTS_1100/tabpVGUE").Select
EndFunc

Func _ComponentsClick()
    Call(_ConnectToSAP())    
    ConsoleWrite("Click Component Tab" & @CRLF)
    $sapSession.findById("wnd[0]/usr/subSUB_ALL:SAPLCOIH:3001/ssubSUB_LEVEL:SAPLCOIH:1100/tabsTS_1100/tabpMUEB").Select
EndFunc

Func _PartnerClick()
    Call(_ConnectToSAP())    
    ConsoleWrite("Click Partner Tab" & @CRLF)
    $sapSession.findById("wnd[0]/usr/subSUB_ALL:SAPLCOIH:3001/ssubSUB_LEVEL:SAPLCOIH:1100/tabsTS_1100/tabpPARU").Select
EndFunc

Func _LocationClick()
    Call(_ConnectToSAP())
    ConsoleWrite("Click Location Tab" & @CRLF)    

     $sapSession.findById("wnd[0]/usr/subSUB_ALL:SAPLCOIH:3001/ssubSUB_LEVEL:SAPLCOIH:1100/tabsTS_1100/tabpILOA").Select
EndFunc

Posted

Welcome to AutoIt and the forum!

When posting code please add code tags (by using the blue AutoIt icon in the editor). Will greatly enhance readability :)

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...