I would like to establish a SAP UDF post, considering the amount of discussion so far on how to automate SAP.
I recently discovered how to access SAP's Scripting COM object through AutoIT, and began writing this UDF to support it.
My time with SAP is limited to working hours so I'll post updates whenever I get the chance. REQUIREMENTS:
AutoIt3 3.2 or higher,
SAP GUI Release 6.40,
SAP GUI Scripting interface is enabled
You are already logged into SAP (ie. The "SAP Easy Access" window is displayed)
To enable the SAP GUI Scripting interface:
From the SAP GUI, select the "Customize Local Layout" button on the toolbar
Select "Options".
Select the "Scripting" tab.
If the message "Scripting is installed!" is not displayed, then contact your SAP administrators to have SAP GUI Scripting installed.
Select "Enable Scripting".
Deselect "Notify when a script attaches to a running GUI".
Deselect "Notify when a script opens a connection".
LIST OF FUNCTIONS:
EXAMPLES: _SAPSessAttach.au3_SAPSessCreate.au3_SAPVKeysSend.au3_SAPVKeysSendUntilWinExists.au3_SAPObjSelect.au3_SAPObjValueSet.au3_SAPObjValueGet.au3_SAPObjPropertySet.au3_SAPObjPropertyGet.au3_SAPWinExists.au3_SAPWinClose.au3
The following code is a simple example of using the UDF.
Ensure you have met the requirements outlined in the REQUIREMENTS section above before commencing.
#include <SAP.au3>
_SAPSessAttach("SAP Easy Access")
_SAPSessCreate("pa30")
_SAPObjValueSet("usr/subSUBSCR_PERNR:SAPMP50A:0120/ctxtRP50G-PERSONID_EXT", "00000018")
_SAPVKeysSend("Enter")
$pers_no = _SAPObjValueGet("usr/subSUBSCR_PERNR:SAPMP50A:0120/ctxtRP50G-PERSONID_EXT")
The first function is _SAPSessAttach. This establishes a connection to a SAP window. In the example, we connect to the first SAP window displayed after logging in to SAP - the SAP Easy Access window.
From here, all other functions will operate within this SAP window / session. _SAPSessCreate then opens a new SAP session, and runs a transaction within it. In the example, this takes us to the Maintain HR Master Data screen (transaction pa30). _SAPObjValueSet sets the value of an object / control within the current SAP window. In the example, this sets the Personnel no. field to 00000018.
To determine the ID of a SAP Object (ie. the Personnel no. field ID "usr/subSUBSCR_PERNR:SAPMP50A:0120/ctxtRP50G-PERSONID_EXT"), follow these manual steps in SAP:
Select the "Customize Local Layout" button on the toolbar.
Select "Script Development Tools".
Select "Do a hit test on the window".
Move your mouse to the object you want the ID of.
Click "Copy Id" in the Scripting Wizard.
Paste this ID into the function in your script.
Remove all text upto and including "wnd[n]/".
_SAPVKeysSend is then used to press the Enter key, and update the Maintain HR Master Data screen with the employee's details.
The last line of the example gets the value of the Personnel no. field, using _SAPObjValueGet. DOWNLOAD:
Latest Version - v0.4 (07/01/09) SAP.au3
SAP.au3