Jump to content

Recommended Posts

Posted (edited)

This is a work in progress.

I am automating the SAP GUI for 10+ years and was using VB.NET, but now we are using Autoit. This UDF was developed by me and is constantly evolving. It includes a detailed log with information about the object and values, old and new if any.

I am open to all the suggestions, so do not be shy with comments.

List of functions in this UDF:

Spoiler

SAP INTERACTION:

  • SAPlogIN($user, $password, $server = Default, $GUIversion = Default)
  • SAPlogOFF($SAPconnection = Default)
  • SAP_StartTransaction($TempSession, $tCode, $timeOut = 10, $sWinWaitTitle = "")
  • SAP_ElementInteraction($TempSession, $uiElement, $interaction, $value = "", $iWait = 10, $hWindow = "", $sWinStartTitle = "", $sWinWaitTitle = "")
  • SAP_GetServerList($type = "XML")
  • WriteToLog($filePath, $value, $mode = 1, $borders = 0, $borderStyle = "=")

SE16 Transaction based:

  • SAPtable2file($SAPsession, $tableName, $destFolder, $destFileName = Default, $outFormat = 2)
  • SAPtable2array($SAPsession, $tableName)

Internal functions used by UDF:

  • RecursiveCheck($startPoint, $searchPath = "")
  • _msToTime($milisec, $includeMs = 1)
  • _MS_StringToMultiDimArray($string, $rowSplit, $columnSplit)

And in case of exception (COM Error):

  • ErrorCatch()

I M P O R T A N T ! ! !

  1. $g_eventerror is a GLOBAL variable that will initialize with the value = 0, but if there is an error the value will change to 1. Based on this you have to reset the value to 0 after the inspection if there was an error and you are handling it.
  2. Use SAPlogIN function to attach to the session or to login into the SAP system. This function will even start the SAP Logon (Pad) if it is not started. If you already have a session just put the username and "" for password.
    Why do you have to use a username? If there are already connections to the SAP system this function will test if the user, that you stated as a parameter, is already logged in. If not it will initiate the login procedure, if the user is logged in it will attach to the desired connection.
    Connection: This function is returning the object for the connection to the SAP server/system, not the session! You will have to make a hook to the session on your own. This was made that way so you can open multiple sessions (windows) and work in multiple sessions from one script. Check the example section.
    If you check the console output there will be a list of useful info about the system which you can further use in your projects. Check the code if interested in the syntax.
  3. $writeToLog is a GLOBAL variable. By default, it is set to True. This variable will determine if WriteToLog function will write to a log.
  4. WriteToLog, this function is used by UDF and will write a detailed log to the provided path. If the path is not provided the log will be written to the Desktop! If $writeToLog is False then the function will not write to log. You can use this if you are doing the inspection of GuiGrid, for example, and do not want to write to a log.

Examples:
 

Spoiler

 

  • Log in to a session from the start:

 

$connection = SAPlogIN(username, password, menu_item_from_SAP_Login)
$session = $connection.Children(0)

 

For the examples below you have to provide the $session (the window you want to control).

  • Element interaction:
SAP_ElementInteraction($session, "wnd[0]/usr/radPNPTIMR1", "select")
SAP_ElementInteraction($session, "wnd[0]/usr/ctxtPNPSTAT2-LOW", "text", "3")
SAP_ElementInteraction($session, "wnd[0]/usr/btn%_PNPPERSG_%_APP_%-VALU_PUSH", "press", "", Default, $hWhandleA, "", "Multiple Selection for Employee group")
SAP_ElementInteraction($session, "wnd[1]/tbar[0]/btn[16]", "press", Default, $hWhandleA, "", "Multiple Selection for Employee group")
SAP_ElementInteraction($session, "wnd[1]/usr/tabsTAB_STRIP/tabpSIVA/ssubSCREEN_HEADER:SAPLALDB:3010/tblSAPLALDBSINGLE/ctxtRSCSEL_255-SLOW_I[1,0]", "text", "1")
SAP_ElementInteraction($session, "wnd[1]/usr/tabsTAB_STRIP/tabpSIVA/ssubSCREEN_HEADER:SAPLALDB:3010/tblSAPLALDBSINGLE/ctxtRSCSEL_255-SLOW_I[1,1]", "text", "2")
SAP_ElementInteraction($session, "wnd[1]/tbar[0]/btn[8]", "press", Default, $hWhandleA, "", "Multiple Selection for Employee group")
SAP_ElementInteraction($session, "wnd[0]/tbar[1]/btn[8]", "press")

This will create a log like this:

2023/05/02 15:02:27 - OK - "select" interaction on element "Time Period Indicator: Today", Type: GuiRadioButton (41), Path: wnd[0]/usr/radPNPTIMR1
2023/05/02 15:02:27 - OK - "text" interaction on element "Employment Status", Type: GuiCTextField (32), Path: wnd[0]/usr/ctxtPNPSTAT2-LOW, Text: "3", New Text: "3" (already set)
2023/05/02 15:02:28 - OK - "press" interaction on element "Multiple Selection (Active)", Type: GuiButton (40), Path: wnd[0]/usr/btn%_PNPPERSG_%_APP_%-VALU_PUSH
2023/05/02 15:02:28 - OK - "press" interaction on element "Delete Entire Selection   (Shift+F4)", Type: GuiButton (40), Path: wnd[1]/tbar[0]/btn[16], Text: ""
2023/05/02 15:02:28 - OK - "text" interaction on element "", Type: GuiCTextField (32), Path: wnd[1]/usr/tabsTAB_STRIP/tabpSIVA/ssubSCREEN_HEADER:SAPLALDB:3010/tblSAPLALDBSINGLE/ctxtRSCSEL_255-SLOW_I[1,1], Text: "", New Text: "2"
2023/05/02 15:02:28 - OK - "text" interaction on element "", Type: GuiCTextField (32), Path: wnd[1]/usr/tabsTAB_STRIP/tabpSIVA/ssubSCREEN_HEADER:SAPLALDB:3010/tblSAPLALDBSINGLE/ctxtRSCSEL_255-SLOW_I[1,2], Text: "", New Text: "3"
2023/05/02 15:02:28 - OK - "press" interaction on element "Copy   (F8)", Type: GuiButton (40), Path: wnd[1]/tbar[0]/btn[8], Text: ""
2023/05/02 15:02:28 - OK - "press" interaction on element "Execute   (F8)", Type: GuiButton (40), Path: wnd[0]/tbar[1]/btn[8]

As you see, this function is picking up any descriptive text from the object, and its type also.

  • Start/Open a transaction:
SAP_StartTransaction($session, $sTcode)

 

This it for this post.

 

MS_SAPfunctions.au3

Edited by LittleMickey74
Update
Posted (edited)

More help:

SAP_ElementInteraction, it is important to mention that the status of the session will be checked (if it is busy or not), the availability of the object is checked, and also (recursive check) if the interaction with the object is possible (if it is not disabled). It will also highlight the error object (red border) if there is an error.If all the previous is OK, one of the following interactions can be applied, for now:

  • "select" - value for this can be True or False, depending on if you want to select or deselect.
  • "click" OR "press" - initiate a button press.
  • "text" Or "set" - sets the value of the textbox or combobox (auto detect), it enters text in the field.
  • "get" Or "read" - reads the text property of the object, reads the textbox or label for example.

More specialized:

  • "selectContextMenuItem"
  • "pressToolbarContextButton"
  • "pressToolbarButton"
  • "selectColumn"
  • "getAbsoluteRow"

 

RETURN CODES:
0 - FAILED
1 - SUCCESS

 

SAPlogOFF, this function can log you off the current connection (all the sessions from that connection) if you put connection as a parameter or, if call it without parameters it will log you off completely, all the connections and all sessions will be closed.

Edited by LittleMickey74
Posted (edited)

Please do not hesitate to ask how to do certain things and I will accept the proposals for further updates.

I use three tools to get the script and to identify elements:

1. Script recorder that is available inside SAP GUI: Customize Local Layout (ALT+F12) => Script Recording and Playback

2. SAP GUI Property Collector - this comes with the SAP GUI installation, ask your admin, for locations (for example version 7.70):
32 bit: <Drive>:\...\BD_NW_7.0_Presentation_7.70_Comp._1_\PRES1\GUI\Windows\Win32\NWBC770\x32\
64 bit: <Drive>:\...\BD_NW_7.0_Presentation_7.70_Comp._1_\PRES1\GUI\Windows\Win32\NWBC770\x64\
NwbcPropertyCollector.exe

3. "Scripting Tracker" is an awesome tool that will help you a lot in the automation of the SAP GUI. It can/has:

  • identify objects
  • dump the object properties
  • has a full list of methods and properties available in SAP GUI
  • has a recorder and can get you the output in several languages, Autoit is one of them

Download link: https://tracker.stschnell.de/#download

Happy coding

Edited by LittleMickey74
Posted

Looks great!

According to AutoIt's "Best Coding Practices" I suggest to use the Hungarian Notation for variables in your UDF.

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

 

  • LittleMickey74 changed the title to SAP UDF - Approach from SAP GUI side

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...