Jump to content

Recommended Posts

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

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]/".
Hello, could you help me ... i tried these steps.

First, Scripting is enabled and i deselect the both notify-options.

but if i try to get an ID by script development tools, i click on "do a hit test on the window" nothing happens.

if i try 2nd method, "troubleshoot sap gui scripting", the wizard tells me, that "Scripting is disabled on the server" ... can i do anything, to use your udf with sap?

Share this post


Link to post
Share on other sites

Hi,

I have the same problem at work too. The UDF works great on the maintenance environment, but not in production......(:-((

Without scripting enabled on the server you can not use this UDF...........as far i i found out the last few days.......

Grtz,

Jeweetwel

Hello, could you help me ... i tried these steps.

First, Scripting is enabled and i deselect the both notify-options.

but if i try to get an ID by script development tools, i click on "do a hit test on the window" nothing happens.

if i try 2nd method, "troubleshoot sap gui scripting", the wizard tells me, that "Scripting is disabled on the server" ... can i do anything, to use your udf with sap?

Share this post


Link to post
Share on other sites

Hi,

I have the same problem at work too. The UDF works great on the maintenance environment, but not in production......(:-((

Without scripting enabled on the server you can not use this UDF...........as far i i found out the last few days.......

Grtz,

Jeweetwel

Hi Jeweetwel,

thank you for your replay, .. that ... that sucks =/

then i have to continue working with controlsend ;-)

but why i get this error?

_SAPSessAttach("SAP Easy Access")

o:\AutoIt\Includes\SAP.au3 (111) : ==> Variable must be of type "Object".:
$sapapp = $sapgui.GetScriptingEngine
$sapapp = $sapgui^ ERROR

Share this post


Link to post
Share on other sites

Hi Jeweetwel,

thank you for your replay, .. that ... that sucks =/

then i have to continue working with controlsend ;-)

but why i get this error?

_SAPSessAttach("SAP Easy Access")

o:\AutoIt\Includes\SAP.au3 (111) : ==> Variable must be of type "Object".:
$sapapp = $sapgui.GetScriptingEngine
$sapapp = $sapgui^ ERROR
Hello,

I can not tell you, because i don't know. In the few minutes of free time i have, i'm playing with autoit, but i'm no expert, so Sean will have to answer this one i think.

Best regards,

Jeweetwel.

Share this post


Link to post
Share on other sites

Hi Jeweetwel,

thank you for your replay, .. that ... that sucks =/

then i have to continue working with controlsend ;-)

but why i get this error?

_SAPSessAttach("SAP Easy Access")

o:\AutoIt\Includes\SAP.au3 (111) : ==> Variable must be of type "Object".:
$sapapp = $sapgui.GetScriptingEngine
$sapapp = $sapgui^ ERROR
This error is saying that $sapgui must be type object which it would be if scripting was enable on your server. But since it is not the variable is not the right type and fails.

Welcome to my world....scripting SAP without scripting enabled.

Negative1


What are we going to do tonight Brain?Same thing we do every night Pinky try to automate the world.

Share this post


Link to post
Share on other sites

Hi Sean,

I've already posted a topic in the general forums but there was some suggestion that I might find better luck solving my problem if I posted to this thread.

Previous Thread:

http://www.autoitscript.com/forum/index.ph...m+error+handler

I have alittle snippet of code that I'm trying to use to create a large number of networks on a Test SAP environment.

My code is hanging and I'm pretty sure I'm close, but am overlooking something simplistic.

I can get into the CN21 transaction but i'm unable to get autoit to fill out any of the boxes on the scren.

Autoit is showing an error on line 446 of the SAP UDF.

$sap_session.findbyID("wnd[" &sap_window_num & "]/" & $object_id).text = $object_value

$sap_session.findbyID("wnd[" &sap_window_num & "]/" & $object_id)^ ERROR

Question about using the "SAPSessAttach" function, when does it need to be used? If I have a single SAP screen at the "SAP Easy Access" and attach to that session, if I navigate into other transactions or the window title changes do I need to run the function again to re-attach as the window title's changed?

Also, how important are the sleep commands? Will the script understand when it's ready to execute the next line or should it be used only when waiting for new windows to appear?

Here's some sample code of my script. I have a feeling the error message means that the script is trying to enter some text into the box but it can't find the box and so it doesn't know what to do.

Any ideas?

~~~~~~~~~~~~~~~~~~~;
#include <SAP.au3>
#include <IE.au3>
_IEErrorHandlerRegister()



;----------------------------------------------------------------------------------------------
;----------------------------------------------------------------------------------------------
;----------------------------------------------------------------------------------------------
;----------------------------------Beginning of Program functions.-----------------------------
;----------------------------------------------------------------------------------------------
;----------------------------------------------------------------------------------------------
        Opt("WinWaitDelay", 100)
        Opt("WinTitleMatchMode", 4)
        Opt("WinDetectHiddenText", 1)
        Opt("MouseCoordMode", 0)
        WinWait("[CLASS:SAP_FRONTEND_SESSION]", "")
        If Not WinActive("[CLASS:SAP_FRONTEND_SESSION]", "") Then WinActivate("[CLASS:SAP_FRONTEND_SESSION]", "")
        WinWaitActive("[CLASS:SAP_FRONTEND_SESSION]", "")

        ; Before running this script, ensure the "SAP Easy Access" window is open.

        ; Attach to the session with the window titled "SAP Easy Access"
        _SAPSessAttach("SAP Easy Access")

        ; Put the value "/ncn21" into the command field.
        _SAPObjValueSet("tbar[0]/okcd", "/ncn21")
        
        Sleep(250)

        ;Go into CN21 Transaction
        _SAPVKeysSend("Enter")
        Sleep(2500)
        

; Attach to the session with the window titled "SAP Easy Access"
        _SAPSessAttach("Create: Network: Initial Screen")
        ;_SAPSessAttach("", "cn21")
        Sleep(250)
        _SAPObjValueSet("/ses[0]/wnd[0]", "XXXXXX") ;ID removed
        _SAPObjValueSet("/usr/ctxtCAUFVD-PROFID", "XXXXX") ;Profile ID removed
        Sleep(250)
        _SAPObjValueSet("/usr/ctxtAUFPAR-PS_AUFART", "Z350")
        Sleep(250)
        _SAPObjValueSet("/usr/ctxtCAUFVD-WERKS", "1101")
        Sleep(250)
        _SAPObjValueSet("/usr/ctxtCAUFVD-DISPO", "001")
        Sleep(250)
        _SAPObjValueSet("/usr/ctxtRC62C-REFNR", "2290300")
        Sleep(300)
        _SAPObjSelect("/usr/btn%_AUTOTEXT002")

        ; Attach to the session with the window titled "Copy From..." and select WBS element and Settlement Rule radio's.
        _SAPSessAttach("Copy from...")
        Sleep(250)
        _SAPObjPropertySet("/usr/chkRC62C-COPY_ASSG", "WBS elem./Sales ord.", True)
        Sleep(250)
        _SAPObjPropertySet("/usr/chkRC62C-COPY_SM", "Settlement Rule", True)
        Sleep(250)
        _SAPObjSelect("/tbar[0]/btn[0]")
        Sleep(250)
        ; Attach to the session with the window titled "Network Create: Header Data" and change the Network Header
        _SAPSessAttach("Network Create: Header Data")
        Sleep(250)
        ;Exit back to the SAP Easy Access Screen
        _SAPVKeysSend("F12")
        ;Go to Excel and copy the next network#
        WinWait("Microsoft Excel", "")
        If Not WinActive("Microsoft Excel", "") Then WinActivate("Microsoft Excel", "")
        WinWaitActive("Microsoft Excel", "")
        Sleep(150)
        Send("{DOWN}")
        Sleep(150)

        ; Source code for exporting SAP Network is done.
        $networkqty = $networkqty + 1
        Sleep(150)
        ;Stop Looping until User Value is met.
    Until $networkqty = $networkqtyend



    ; Display Print Message Because you're all done.
    MsgBox(0, "SAP Network Exporter", "Finished!")
    Exit
EndIf</div>

Using IE's Com Error handler the following is spewed out.

Running AU3Check (1.54.14.0)  from:C:\Program Files\AutoIt3
+>16:29:46 AU3Check ended.rc:0
--> COM Error Encountered in SAP Network Creator.au3
----> $IEComErrorScriptline = 447
----> $IEComErrorNumberHex = 80020009
----> $IEComErrorNumber = -2147352567
----> $IEComErrorWinDescription = 
----> $IEComErrorDescription = The control could not be found by id.
----> $IEComErrorSource = SAP Frontend Server
----> $IEComErrorHelpFile = C:\Program Files\SAP\FrontEnd\SAPgui\sapfront.HLP
----> $IEComErrorHelpContext = 393215
----> $IEComErrorLastDllError = 0

--> COM Error Encountered in SAP Network Creator.au3
----> $IEComErrorScriptline = 447
----> $IEComErrorNumberHex = 80020009
----> $IEComErrorNumber = -2147352567
----> $IEComErrorWinDescription = 
----> $IEComErrorDescription = The control could not be found by id.
----> $IEComErrorSource = SAP Frontend Server
----> $IEComErrorHelpFile = C:\Program Files\SAP\FrontEnd\SAPgui\sapfront.HLP
----> $IEComErrorHelpContext = 393215
----> $IEComErrorLastDllError = 0

--> COM Error Encountered in SAP Network Creator.au3
----> $IEComErrorScriptline = 447
----> $IEComErrorNumberHex = 80020009
----> $IEComErrorNumber = -2147352567
----> $IEComErrorWinDescription = 
----> $IEComErrorDescription = The control could not be found by id.
----> $IEComErrorSource = SAP Frontend Server
----> $IEComErrorHelpFile = C:\Program Files\SAP\FrontEnd\SAPgui\sapfront.HLP
----> $IEComErrorHelpContext = 393215
----> $IEComErrorLastDllError = 0

--> COM Error Encountered in SAP Network Creator.au3
----> $IEComErrorScriptline = 447
----> $IEComErrorNumberHex = 80020009
----> $IEComErrorNumber = -2147352567
----> $IEComErrorWinDescription = 
----> $IEComErrorDescription = The control could not be found by id.
----> $IEComErrorSource = SAP Frontend Server
----> $IEComErrorHelpFile = C:\Program Files\SAP\FrontEnd\SAPgui\sapfront.HLP
----> $IEComErrorHelpContext = 393215
----> $IEComErrorLastDllError = 0

--> COM Error Encountered in SAP Network Creator.au3
----> $IEComErrorScriptline = 447
----> $IEComErrorNumberHex = 80020009
----> $IEComErrorNumber = -2147352567
----> $IEComErrorWinDescription = 
----> $IEComErrorDescription = The control could not be found by id.
----> $IEComErrorSource = SAP Frontend Server
----> $IEComErrorHelpFile = C:\Program Files\SAP\FrontEnd\SAPgui\sapfront.HLP
----> $IEComErrorHelpContext = 393215
----> $IEComErrorLastDllError = 0

--> COM Error Encountered in SAP Network Creator.au3
----> $IEComErrorScriptline = 364
----> $IEComErrorNumberHex = 80020009
----> $IEComErrorNumber = -2147352567
----> $IEComErrorWinDescription = 
----> $IEComErrorDescription = The control could not be found by id.
----> $IEComErrorSource = SAP Frontend Server
----> $IEComErrorHelpFile = C:\Program Files\SAP\FrontEnd\SAPgui\sapfront.HLP
----> $IEComErrorHelpContext = 393215
----> $IEComErrorLastDllError = 0

+>16:30:18 AutoIT3.exe ended.rc:0
+>16:30:20 AutoIt3Wrapper Finished
>Exit code: 0    Time: 36.192
</div>

Thanks in advance,

Edited by Teltech

Share this post


Link to post
Share on other sites

Hi Sean,

We are waiting for your reply.

Tks,

LVD

Are you having the same problem lev?

I'm sure Sean's busy this time a year... Let's be patient...

Share this post


Link to post
Share on other sites

I have followed all pre-reqs and I as well cannot attach to a session. Though, I did turn back on NOTIFY when trying to attach in SAP and when I run the script, sure enough, it pops up a box asking if I want to all an attach, regardless of my answer, the script returns that it cannot find the window. But I know it's finding it due to the message. So I turn the notify options back off and still no connection. What am I missing?

Share this post


Link to post
Share on other sites

I have followed all pre-reqs and I as well cannot attach to a session. Though, I did turn back on NOTIFY when trying to attach in SAP and when I run the script, sure enough, it pops up a box asking if I want to all an attach, regardless of my answer, the script returns that it cannot find the window. But I know it's finding it due to the message. So I turn the notify options back off and still no connection. What am I missing?

No idea, have some sample code? I'll take a boo and see if it works on my machines. What SAP version are you running?

Share this post


Link to post
Share on other sites

Dear Sean,

I get the same problem with Negative1. Could you check.

Thanks and regards,

LVD

Sorry for the really really late reply. Been very busy at my day job and not much time to work on the UDF.

I'm not sure why you and Negative1 are getting the "Variable must be of type "Object"." error. I haven't been able to reproduce this error, though I only have access to SAP GUI 640 at my work. We did have SAP GUI 710 for a few weeks, but it has been since taken away, and I can no longer test my UDF with it.

I suspect this is a problem related to 710. I have run your script and make it this far through your script:

WinActivate("SAP Easy Access")

; Before running this script, ensure the "SAP Easy Access" window is open.
; Attach to the session with the window titled "SAP Easy Access"
_SAPSessAttach("SAP Easy Access")

; Put the value "/nmb52" into the command field.
_SAPObjValueSet("tbar[0]/okcd", "/nmb52")

; Press the "Enter" key.
_SAPVKeysSend("Enter")
; Set some fields
; Field Plant: 9068
_SAPObjValueSet("usr/ctxtWERKS-LOW","9068")
; Field Layout: ALVD
_SAPObjValueSet("usr/ctxtP_VARI","ALVD")
; Press Enter then F8 to run this T-Code
_SAPVKeysSend("Enter")
_SAPVKeysSend("F8")

At this point SAP gives me a "No entry was found for the entry in field Plant" warning in the SAP status bar, and the "Display warehouse stocks of material" screen is not displayed. This is probably because my SAP config. is different to yours, and I'm missing some prerequisite data that makes this script work in your SAP environment. I'm not familiar with these transactions enough to work around the data issue. I only have knowledge of the HR module in SAP.

It looks like Negative1 is getting an error within the function "_SAPObjValueSet". Are you getting the same error in the same function? I was successful in running the _SAPObjValueSet function in your script.

I'd love to test my UDF under SAP GUI 710. Maybe I'll be able to one day.


Cheers, Sean.

See my other UDFs:

Chrome UDF - Automate Chrome | SAP UDF - Automate SAP | Java UDF - Automate Java Applications & Applets | Tesseract (OCR) UDF - Capture text from applications, controls and the desktop | Textract (OCR) UDF - Capture text from applications and controls | FileSystemMonitor UDF - File, Folder, Drive and Shell Monitoring | VLC (Media Player) UDF - Creating and controlling a VLC control in AutoIT | Google Maps UDF - Creating and controlling Google Maps (inc. GE) in AutoIT | SAPIListBox (Speech Recognition) UDF - Speech Recognition via the Microsoft Speech (SAPI) ListBox | eBay UDF - Automate eBay using the eBay API | ChildProc (Parallel Processing) UDF - Parallel processing functions for AutoIT | HyperCam (Screen Recording) UDF - Automate the HyperCam screen recorder | Twitter UDF - Automate Twitter using OAuth and the Twitter API | cURL UDF - a UDF for transferring data with URL syntax

See my other Tools:

Rapid Menu Writer - Add menus to DVDs in seconds | TV Player - Automates the process of playing videos on an external TV / Monitor | Rapid Video Converter - A tool for resizing and reformatting videos | [topic130531]Rapid DVD Creator - Convert videos to DVD fast and for free | ZapPF - A tool for killing processes and recycling files | Sean's eBay Bargain Hunter - Find last minute bargains in eBay using AutoIT | Sean's GUI Inspector - A scripting tool for querying GUIs | TransLink Journey Planner with maps - Incorporating Google Maps into an Australian Journey Planner | Automate Qt and QWidgets | Brisbane City Council Event Viewer - See what's going on in Brisbane, Australia

Share this post


Link to post
Share on other sites

This error is saying that $sapgui must be type object which it would be if scripting was enable on your server. But since it is not the variable is not the right type and fails.

Welcome to my world....scripting SAP without scripting enabled.

Negative1

Thanks for replying while I've been away. Was your problem to do with SAP scripting being disabled Negative1?

Yes if anyone receives the following error, it means you have not got SAP scripting enabled on your server:

$sapapp = $sapgui.GetScriptingEngine
$sapapp = $sapgui^ ERROR

I can reproduce this error myself by disabling the Scripting option in my SAP client, while Scripting is still enabled on the server.

It's a prerequisite of the UDF to have Scripting enabled. The UDF will not work without it. I use SAP daily in a testing environment, and it was easy to make a request to have scripting enabled. Scripting is also being enabled in our production environment, because my UDF has been recommended to our client as a means of automating data entry into SAP from their legacy payroll system (in cases where the data migration may have failed).

I can see this error message is ugly and confusing to people. I need to update the UDF to catch this error and display something more friendly in the console I think. Something like "A connection to the SAP scripting engine failed. Please check that you have SAP Scripting enabled".

Trying to automate SAP without SAP Scripting is an aweful job. This is how I began automating SAP until I discovered one day that SAP has a scripting interface. To automate SAP without this UDF requires the use of AutoIT's keyboard, window and mouse functions send keystrokes and mouse clicks to the SAP window. It's a fairly good way to automate SAP, but it can be very tricky, especially in some SAP windows which have a poor tabbing sequence that doesn't allow you to find the correct control every time. Another benefit of using this UDF, and SAP Scripting, is that SAP is automated in the background. You can be working in other windows and applications in front of SAP while SAP is being automated. That's the power of COM objects, and AutoIT's support of them.

Edited by seangriffin

Cheers, Sean.

See my other UDFs:

Chrome UDF - Automate Chrome | SAP UDF - Automate SAP | Java UDF - Automate Java Applications & Applets | Tesseract (OCR) UDF - Capture text from applications, controls and the desktop | Textract (OCR) UDF - Capture text from applications and controls | FileSystemMonitor UDF - File, Folder, Drive and Shell Monitoring | VLC (Media Player) UDF - Creating and controlling a VLC control in AutoIT | Google Maps UDF - Creating and controlling Google Maps (inc. GE) in AutoIT | SAPIListBox (Speech Recognition) UDF - Speech Recognition via the Microsoft Speech (SAPI) ListBox | eBay UDF - Automate eBay using the eBay API | ChildProc (Parallel Processing) UDF - Parallel processing functions for AutoIT | HyperCam (Screen Recording) UDF - Automate the HyperCam screen recorder | Twitter UDF - Automate Twitter using OAuth and the Twitter API | cURL UDF - a UDF for transferring data with URL syntax

See my other Tools:

Rapid Menu Writer - Add menus to DVDs in seconds | TV Player - Automates the process of playing videos on an external TV / Monitor | Rapid Video Converter - A tool for resizing and reformatting videos | [topic130531]Rapid DVD Creator - Convert videos to DVD fast and for free | ZapPF - A tool for killing processes and recycling files | Sean's eBay Bargain Hunter - Find last minute bargains in eBay using AutoIT | Sean's GUI Inspector - A scripting tool for querying GUIs | TransLink Journey Planner with maps - Incorporating Google Maps into an Australian Journey Planner | Automate Qt and QWidgets | Brisbane City Council Event Viewer - See what's going on in Brisbane, Australia

Share this post


Link to post
Share on other sites

Hi Sean,

I've already posted a topic in the general forums but there was some suggestion that I might find better luck solving my problem if I posted to this thread.

Previous Thread:

http://www.autoitscript.com/forum/index.ph...m+error+handler

I have alittle snippet of code that I'm trying to use to create a large number of networks on a Test SAP environment.

My code is hanging and I'm pretty sure I'm close, but am overlooking something simplistic.

I can get into the CN21 transaction but i'm unable to get autoit to fill out any of the boxes on the scren.

Autoit is showing an error on line 446 of the SAP UDF.

$sap_session.findbyID("wnd[" &sap_window_num & "]/" & $object_id).text = $object_value

$sap_session.findbyID("wnd[" &sap_window_num & "]/" & $object_id)^ ERROR

Question about using the "SAPSessAttach" function, when does it need to be used? If I have a single SAP screen at the "SAP Easy Access" and attach to that session, if I navigate into other transactions or the window title changes do I need to run the function again to re-attach as the window title's changed?

Also, how important are the sleep commands? Will the script understand when it's ready to execute the next line or should it be used only when waiting for new windows to appear?

Here's some sample code of my script. I have a feeling the error message means that the script is trying to enter some text into the box but it can't find the box and so it doesn't know what to do.

Any ideas?

CODE
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

~~~~~~~~~~~~~~~~~~~~~~~~~~~~;

; SAP Network Creator

; Version: 1.0

;

; Script Function:

; Creates SAP Networks for SQ1

;

; CTRL + ALT + X to close the program at any time.

;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

~~~~~~~~~~~~~~~~~~~;

#include <Misc.au3>

#include <SAP.au3>

#include <IE.au3>

_IEErrorHandlerRegister()

; Check to see if the script is running, close it after notifying the user.

If _Singleton("MyScriptName", 1) = 0 Then

MsgBox(0, "Script Name", "This program is already running. Having more than one copy open is not allowed.")

Exit

EndIf

; Set CTRL + ALT + X hotkey to close program.

HotKeySet("^!x", "MyExit")

Func MyExit()

Exit

EndFunc ;==>MyExit

;----------------------------------------------------------------------------------------------

;----------------------------------------------------------------------------------------------

;----------------------------------------------------------------------------------------------

;----------------------------------Beginning of Program functions.-----------------------------

;----------------------------------------------------------------------------------------------

;----------------------------------------------------------------------------------------------

; Prompt the user to run the script - use a Yes/No prompt

$question = MsgBox(4, "SAP Network Creator", "This Program will Creat SAP networks using the CN21 transaction..")

; Check the user's answer to the prompt

; If "No" was clicked (7) then exit the script

If $question = 7 Then

MsgBox(4096, "SAP Network Creator", "Bye!")

Exit

EndIf

; Present user with a textbox to enter Numbers.

$answer = InputBox("SAP Network Exporter", "How many Networks do you want to Create? Hit CTRL + ALT + X at any time to stop the script.", "Enter Number of Networks Here.", " M3")

If @error = 1 Then

MsgBox(4096, "Error", "Goodbye!")

Exit

$networkqty = 0 ;Start count variable.

$networkqtyend = $answer ;Specify end variable that is user defined.

ElseIf @error = 0 Then

Do ; Start Executing SAP export Command Lines.

Opt("WinWaitDelay", 100)

Opt("WinTitleMatchMode", 4)

Opt("WinDetectHiddenText", 1)

Opt("MouseCoordMode", 0)

WinWait("[CLASS:SAP_FRONTEND_SESSION]", "")

If Not WinActive("[CLASS:SAP_FRONTEND_SESSION]", "") Then WinActivate("[CLASS:SAP_FRONTEND_SESSION]", "")

WinWaitActive("[CLASS:SAP_FRONTEND_SESSION]", "")

; Before running this script, ensure the "SAP Easy Access" window is open.

; Attach to the session with the window titled "SAP Easy Access"

_SAPSessAttach("SAP Easy Access")

; Put the value "/ncn21" into the command field.

_SAPObjValueSet("tbar[0]/okcd", "/ncn21")

Sleep(250)

;Go into CN21 Transaction

_SAPVKeysSend("Enter")

Sleep(2500)

; Attach to the session with the window titled "SAP Easy Access"

_SAPSessAttach("Create: Network: Initial Screen")

;_SAPSessAttach("", "cn21")

Sleep(250)

_SAPObjValueSet("/ses[0]/wnd[0]", "XXXXXX") ;ID removed

_SAPObjValueSet("/usr/ctxtCAUFVD-PROFID", "XXXXX") ;Profile ID removed

Sleep(250)

_SAPObjValueSet("/usr/ctxtAUFPAR-PS_AUFART", "Z350")

Sleep(250)

_SAPObjValueSet("/usr/ctxtCAUFVD-WERKS", "1101")

Sleep(250)

_SAPObjValueSet("/usr/ctxtCAUFVD-DISPO", "001")

Sleep(250)

_SAPObjValueSet("/usr/ctxtRC62C-REFNR", "2290300")

Sleep(300)

_SAPObjSelect("/usr/btn%_AUTOTEXT002")

; Attach to the session with the window titled "Copy From..." and select WBS element and Settlement Rule radio's.

_SAPSessAttach("Copy from...")

Sleep(250)

_SAPObjPropertySet("/usr/chkRC62C-COPY_ASSG", "WBS elem./Sales ord.", True)

Sleep(250)

_SAPObjPropertySet("/usr/chkRC62C-COPY_SM", "Settlement Rule", True)

Sleep(250)

_SAPObjSelect("/tbar[0]/btn[0]")

Sleep(250)

; Attach to the session with the window titled "Network Create: Header Data" and change the Network Header

_SAPSessAttach("Network Create: Header Data")

Sleep(250)

;Exit back to the SAP Easy Access Screen

_SAPVKeysSend("F12")

;Go to Excel and copy the next network#

WinWait("Microsoft Excel", "")

If Not WinActive("Microsoft Excel", "") Then WinActivate("Microsoft Excel", "")

WinWaitActive("Microsoft Excel", "")

Sleep(150)

Send("{DOWN}")

Sleep(150)

; Source code for exporting SAP Network is done.

$networkqty = $networkqty + 1

Sleep(150)

;Stop Looping until User Value is met.

Until $networkqty = $networkqtyend

; Display Print Message Because you're all done.

MsgBox(0, "SAP Network Exporter", "Finished!")

Exit

EndIf

Using IE's Com Error handler the following is spewed out.

CODE
>"C:\Program Files\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.exe" /run /prod /ErrorStdOut /in "C:\Documents and Settings\t827348\My Documents\Autoit\SAP Network Creator\SAP Network Creator.au3" /autoit3dir "C:\Program Files\AutoIt3" /UserParams

+>16:29:45 Starting AutoIt3Wrapper v.1.10.1.14 Environment(Language:0409 Keyboard:00000409 OS:WIN_XP/Service Pack 2 CPU:X86 ANSI)

>Running AU3Check (1.54.14.0) from:C:\Program Files\AutoIt3

+>16:29:46 AU3Check ended.rc:0

>Running:(3.3.0.0):C:\Program Files\AutoIt3\autoit3.exe "C:\Documents and Settings\t827348\My Documents\Autoit\SAP Network Creator\SAP Network Creator.au3"

--> COM Error Encountered in SAP Network Creator.au3

----> $IEComErrorScriptline = 447

----> $IEComErrorNumberHex = 80020009

----> $IEComErrorNumber = -2147352567

----> $IEComErrorWinDescription =

----> $IEComErrorDescription = The control could not be found by id.

----> $IEComErrorSource = SAP Frontend Server

----> $IEComErrorHelpFile = C:\Program Files\SAP\FrontEnd\SAPgui\sapfront.HLP

----> $IEComErrorHelpContext = 393215

----> $IEComErrorLastDllError = 0

--> COM Error Encountered in SAP Network Creator.au3

----> $IEComErrorScriptline = 447

----> $IEComErrorNumberHex = 80020009

----> $IEComErrorNumber = -2147352567

----> $IEComErrorWinDescription =

----> $IEComErrorDescription = The control could not be found by id.

----> $IEComErrorSource = SAP Frontend Server

----> $IEComErrorHelpFile = C:\Program Files\SAP\FrontEnd\SAPgui\sapfront.HLP

----> $IEComErrorHelpContext = 393215

----> $IEComErrorLastDllError = 0

--> COM Error Encountered in SAP Network Creator.au3

----> $IEComErrorScriptline = 447

----> $IEComErrorNumberHex = 80020009

----> $IEComErrorNumber = -2147352567

----> $IEComErrorWinDescription =

----> $IEComErrorDescription = The control could not be found by id.

----> $IEComErrorSource = SAP Frontend Server

----> $IEComErrorHelpFile = C:\Program Files\SAP\FrontEnd\SAPgui\sapfront.HLP

----> $IEComErrorHelpContext = 393215

----> $IEComErrorLastDllError = 0

--> COM Error Encountered in SAP Network Creator.au3

----> $IEComErrorScriptline = 447

----> $IEComErrorNumberHex = 80020009

----> $IEComErrorNumber = -2147352567

----> $IEComErrorWinDescription =

----> $IEComErrorDescription = The control could not be found by id.

----> $IEComErrorSource = SAP Frontend Server

----> $IEComErrorHelpFile = C:\Program Files\SAP\FrontEnd\SAPgui\sapfront.HLP

----> $IEComErrorHelpContext = 393215

----> $IEComErrorLastDllError = 0

--> COM Error Encountered in SAP Network Creator.au3

----> $IEComErrorScriptline = 447

----> $IEComErrorNumberHex = 80020009

----> $IEComErrorNumber = -2147352567

----> $IEComErrorWinDescription =

----> $IEComErrorDescription = The control could not be found by id.

----> $IEComErrorSource = SAP Frontend Server

----> $IEComErrorHelpFile = C:\Program Files\SAP\FrontEnd\SAPgui\sapfront.HLP

----> $IEComErrorHelpContext = 393215

----> $IEComErrorLastDllError = 0

--> COM Error Encountered in SAP Network Creator.au3

----> $IEComErrorScriptline = 364

----> $IEComErrorNumberHex = 80020009

----> $IEComErrorNumber = -2147352567

----> $IEComErrorWinDescription =

----> $IEComErrorDescription = The control could not be found by id.

----> $IEComErrorSource = SAP Frontend Server

----> $IEComErrorHelpFile = C:\Program Files\SAP\FrontEnd\SAPgui\sapfront.HLP

----> $IEComErrorHelpContext = 393215

----> $IEComErrorLastDllError = 0

+>16:30:18 AutoIT3.exe ended.rc:0

+>16:30:20 AutoIt3Wrapper Finished

>Exit code: 0 Time: 36.192

Thanks in advance,

Hi Teltech,

So sorry for the long delay. I've noticed that I'm not being notified when people post to this topic. I'll have to check my email settings. I've also been snowed under with my day job, but I'm very keen to help everyone with the UDF.

Your getting an error at the line:

_SAPObjValueSet("/usr/ctxtCAUFVD-PROFID", "XXXXX")

because the control ID you've used is actually wrong. You nearly had it right. I went to transaction "cn21" myself in SAP, and did a hit test, and found out the control is named "cmbCAUFVD-PROFID", not "ctxtCAUFVD-PROFID". The control is a combo box, which is why it's named has the "cmb" prefix. The "ctxt" prefix refers to text boxes, like the "Network type" field. The other thing to bare in mind with combo boxes, is that the value you must provide for them in the "_SAPObjValueSet" function is the key only. This is the short text you'll find at the start of every item in the combo box. If I pull down the "Network profile" combo box with my mouse, I see the following two entries:

0000001 Network profile w/ header acct. assignm.

0000002 Network profile w/activity acct. assignm

To select the first item, you need to use the key "0000001" in the "_SAPObjValueSet" function. The final problem with this line in the script is that you've included the forward slash "/" before the text "usr". You'll see in my example on page 1 of this topic that you need to exclude the forward slash at the start of the control name.

A working piece of script is as follows:

#include <SAP.au3>

_SAPSessAttach("SAP Easy Access", "cn21")

_SAPSessAttach("Create: Network: Initial Screen")
_SAPObjValueSet("usr/cmbCAUFVD-PROFID", "0000001")
_SAPObjValueSet("usr/ctxtAUFPAR-PS_AUFART", "XXXX")
_SAPObjValueSet("usr/ctxtCAUFVD-WERKS", "1101")
_SAPObjValueSet("usr/ctxtCAUFVD-DISPO", "001")
_SAPObjValueSet("usr/ctxtRC62C-REFNR", "2290300")

Note that I've include the "cn21" transaction in the _SAPSessAttach function call. This is a fast way to attach to a SAP session and fire a transaction all in one call.

I would recommend using _SAPSessAttach every time the window title changes. Sometimes it's not necessary, and sometimes it is. To be on the safe side, use it everytime the window title changes. There's very small overhead in calling this function.

You should not need to use sleep commands to synchronise SAP windows. The COM object underneath seems to handle this. Every script I've written has worked without sleep commands.


Cheers, Sean.

See my other UDFs:

Chrome UDF - Automate Chrome | SAP UDF - Automate SAP | Java UDF - Automate Java Applications & Applets | Tesseract (OCR) UDF - Capture text from applications, controls and the desktop | Textract (OCR) UDF - Capture text from applications and controls | FileSystemMonitor UDF - File, Folder, Drive and Shell Monitoring | VLC (Media Player) UDF - Creating and controlling a VLC control in AutoIT | Google Maps UDF - Creating and controlling Google Maps (inc. GE) in AutoIT | SAPIListBox (Speech Recognition) UDF - Speech Recognition via the Microsoft Speech (SAPI) ListBox | eBay UDF - Automate eBay using the eBay API | ChildProc (Parallel Processing) UDF - Parallel processing functions for AutoIT | HyperCam (Screen Recording) UDF - Automate the HyperCam screen recorder | Twitter UDF - Automate Twitter using OAuth and the Twitter API | cURL UDF - a UDF for transferring data with URL syntax

See my other Tools:

Rapid Menu Writer - Add menus to DVDs in seconds | TV Player - Automates the process of playing videos on an external TV / Monitor | Rapid Video Converter - A tool for resizing and reformatting videos | [topic130531]Rapid DVD Creator - Convert videos to DVD fast and for free | ZapPF - A tool for killing processes and recycling files | Sean's eBay Bargain Hunter - Find last minute bargains in eBay using AutoIT | Sean's GUI Inspector - A scripting tool for querying GUIs | TransLink Journey Planner with maps - Incorporating Google Maps into an Australian Journey Planner | Automate Qt and QWidgets | Brisbane City Council Event Viewer - See what's going on in Brisbane, Australia

Share this post


Link to post
Share on other sites

I have followed all pre-reqs and I as well cannot attach to a session. Though, I did turn back on NOTIFY when trying to attach in SAP and when I run the script, sure enough, it pops up a box asking if I want to all an attach, regardless of my answer, the script returns that it cannot find the window. But I know it's finding it due to the message. So I turn the notify options back off and still no connection. What am I missing?

No idea, have some sample code? I'll take a boo and see if it works on my machines. What SAP version are you running?

Mercury049,

Can you provide us with some sample code. The problem is likely to be in your script, since you seem to have the prerequisites of the UDF already setup.


Cheers, Sean.

See my other UDFs:

Chrome UDF - Automate Chrome | SAP UDF - Automate SAP | Java UDF - Automate Java Applications & Applets | Tesseract (OCR) UDF - Capture text from applications, controls and the desktop | Textract (OCR) UDF - Capture text from applications and controls | FileSystemMonitor UDF - File, Folder, Drive and Shell Monitoring | VLC (Media Player) UDF - Creating and controlling a VLC control in AutoIT | Google Maps UDF - Creating and controlling Google Maps (inc. GE) in AutoIT | SAPIListBox (Speech Recognition) UDF - Speech Recognition via the Microsoft Speech (SAPI) ListBox | eBay UDF - Automate eBay using the eBay API | ChildProc (Parallel Processing) UDF - Parallel processing functions for AutoIT | HyperCam (Screen Recording) UDF - Automate the HyperCam screen recorder | Twitter UDF - Automate Twitter using OAuth and the Twitter API | cURL UDF - a UDF for transferring data with URL syntax

See my other Tools:

Rapid Menu Writer - Add menus to DVDs in seconds | TV Player - Automates the process of playing videos on an external TV / Monitor | Rapid Video Converter - A tool for resizing and reformatting videos | [topic130531]Rapid DVD Creator - Convert videos to DVD fast and for free | ZapPF - A tool for killing processes and recycling files | Sean's eBay Bargain Hunter - Find last minute bargains in eBay using AutoIT | Sean's GUI Inspector - A scripting tool for querying GUIs | TransLink Journey Planner with maps - Incorporating Google Maps into an Australian Journey Planner | Automate Qt and QWidgets | Brisbane City Council Event Viewer - See what's going on in Brisbane, Australia

Share this post


Link to post
Share on other sites

Hi Teltech,

So sorry for the long delay. I've noticed that I'm not being notified when people post to this topic. I'll have to check my email settings. I've also been snowed under with my day job, but I'm very keen to help everyone with the UDF.

Your getting an error at the line:

_SAPObjValueSet("/usr/ctxtCAUFVD-PROFID", "XXXXX")

because the control ID you've used is actually wrong. You nearly had it right. I went to transaction "cn21" myself in SAP, and did a hit test, and found out the control is named "cmbCAUFVD-PROFID", not "ctxtCAUFVD-PROFID". The control is a combo box, which is why it's named has the "cmb" prefix. The "ctxt" prefix refers to text boxes, like the "Network type" field. The other thing to bare in mind with combo boxes, is that the value you must provide for them in the "_SAPObjValueSet" function is the key only. This is the short text you'll find at the start of every item in the combo box. If I pull down the "Network profile" combo box with my mouse, I see the following two entries:

0000001 Network profile w/ header acct. assignm.

0000002 Network profile w/activity acct. assignm

To select the first item, you need to use the key "0000001" in the "_SAPObjValueSet" function. The final problem with this line in the script is that you've included the forward slash "/" before the text "usr". You'll see in my example on page 1 of this topic that you need to exclude the forward slash at the start of the control name.

A working piece of script is as follows:

#include <SAP.au3>

_SAPSessAttach("SAP Easy Access", "cn21")

_SAPSessAttach("Create: Network: Initial Screen")
_SAPObjValueSet("usr/cmbCAUFVD-PROFID", "0000001")
_SAPObjValueSet("usr/ctxtAUFPAR-PS_AUFART", "XXXX")
_SAPObjValueSet("usr/ctxtCAUFVD-WERKS", "1101")
_SAPObjValueSet("usr/ctxtCAUFVD-DISPO", "001")
_SAPObjValueSet("usr/ctxtRC62C-REFNR", "2290300")

Note that I've include the "cn21" transaction in the _SAPSessAttach function call. This is a fast way to attach to a SAP session and fire a transaction all in one call.

I would recommend using _SAPSessAttach every time the window title changes. Sometimes it's not necessary, and sometimes it is. To be on the safe side, use it everytime the window title changes. There's very small overhead in calling this function.

You should not need to use sleep commands to synchronise SAP windows. The COM object underneath seems to handle this. Every script I've written has worked without sleep commands.

Now I just feel silly :D After removing the "/" everything works like a charm!

There's no need to apologize for being busy. I think everyone's kind of feeling the stress at this time :o

Thank you so much sean! This UDF will definately come in handy. Now that I know what was wrong I can't wait to start playing some more :D

That's a good tip about the _SAPSessAttach, I wasn't sure what was wrong so I thought maybe things were running alittle to quick. I also completely skipped over the fact that you have an error handler it sure makes diagnosing problems easier!

Also in response to the combo/text box question. How are you able to tell that it's a combo box? When I do a hit test it comes back with ctxt. I know there's alittle circle beside the box and if I click on that there's about 10 different options I can double click on, which will fill in the text of the related network status profile. I guess this may be just one of those objects that act like one or the other.

Anyways, thanks again! Another world to explore.

Share this post


Link to post
Share on other sites

Hi Sean,

I've been having a wonderful time using this UDF however I have one small simple question that I'm hoping you can answer. I'm having some problems with the correct syntax for the _SAPObjPropertySet function.

In the CN21 transaction there's an ability to use an existing network as a template.

If you click on the "more" button it prompts a window with about 9 checkboxes. The first and last checkboxes are unmarked and the middle 7 are checked.

I'm able to press the Okay button so I know the script is acknowledging that window. I just don't think I have the correct syntax for the property set function.

From your UDF the syntax is;

_SAPObjPropertySet($object_id, $object_property, $object_value)

My question is. What is an/the object property? Am I using the correct object_property? How do I find it?

The example provided with the UDF uses the word "opened" although I'm not sure what it's really doing there.

I made an assumption it's the text next to the checkbox? but I don't think that's right...... Any ideas?

CODE
; Attach to the session with the window titled "Copy From..." and select WBS element and Settlement Rule checkboxes.

_SAPSessAttach("Copy from...")

_SAPObjPropertySet("usr/chkRC62C-COPY_ASSG", "WBS elem./Sales ord.", True)

_SAPObjPropertySet("usr/chkRC62C-COPY_SM", "Settlement rule", True)

_SAPObjSelect("tbar[0]/btn[0]")

Thanks in advance!

Edited by Teltech

Share this post


Link to post
Share on other sites

Hi Sean,

I've been having a wonderful time using this UDF however I have one small simple question that I'm hoping you can answer. I'm having some problems with the correct syntax for the _SAPObjPropertySet function.

In the CN21 transaction there's an ability to use an existing network as a template.

If you click on the "more" button it prompts a window with about 9 checkboxes. The first and last checkboxes are unmarked and the middle 7 are checked.

I'm able to press the Okay button so I know the script is acknowledging that window. I just don't think I have the correct syntax for the property set function.

From your UDF the syntax is;

_SAPObjPropertySet($object_id, $object_property, $object_value)

My question is. What is an/the object property? Am I using the correct object_property? How do I find it?

The example provided with the UDF uses the word "opened" although I'm not sure what it's really doing there.

I made an assumption it's the text next to the checkbox? but I don't think that's right...... Any ideas?

CODE
; Attach to the session with the window titled "Copy From..." and select WBS element and Settlement Rule checkboxes.

_SAPSessAttach("Copy from...")

_SAPObjPropertySet("usr/chkRC62C-COPY_ASSG", "WBS elem./Sales ord.", True)

_SAPObjPropertySet("usr/chkRC62C-COPY_SM", "Settlement rule", True)

_SAPObjSelect("tbar[0]/btn[0]")

Thanks in advance!

Hi Teltech,

Sounds like all you are trying to do is select checkboxes. Don't use _SAPObjPropertySet. Use the _SAPObjSelect and _SAPObjDeselect functions.

Here's an example that selects (ticks) the first checkbox in your window:

#include <SAP.au3>

_SAPSessAttach("Copy from...")
_SAPObjSelect("usr/chkRC62C-COPY_ASSG")

In the Remarks section of these functions in the UDF you'll see that I've stated that they'll work with GuiCheckBox controls.


Cheers, Sean.

See my other UDFs:

Chrome UDF - Automate Chrome | SAP UDF - Automate SAP | Java UDF - Automate Java Applications & Applets | Tesseract (OCR) UDF - Capture text from applications, controls and the desktop | Textract (OCR) UDF - Capture text from applications and controls | FileSystemMonitor UDF - File, Folder, Drive and Shell Monitoring | VLC (Media Player) UDF - Creating and controlling a VLC control in AutoIT | Google Maps UDF - Creating and controlling Google Maps (inc. GE) in AutoIT | SAPIListBox (Speech Recognition) UDF - Speech Recognition via the Microsoft Speech (SAPI) ListBox | eBay UDF - Automate eBay using the eBay API | ChildProc (Parallel Processing) UDF - Parallel processing functions for AutoIT | HyperCam (Screen Recording) UDF - Automate the HyperCam screen recorder | Twitter UDF - Automate Twitter using OAuth and the Twitter API | cURL UDF - a UDF for transferring data with URL syntax

See my other Tools:

Rapid Menu Writer - Add menus to DVDs in seconds | TV Player - Automates the process of playing videos on an external TV / Monitor | Rapid Video Converter - A tool for resizing and reformatting videos | [topic130531]Rapid DVD Creator - Convert videos to DVD fast and for free | ZapPF - A tool for killing processes and recycling files | Sean's eBay Bargain Hunter - Find last minute bargains in eBay using AutoIT | Sean's GUI Inspector - A scripting tool for querying GUIs | TransLink Journey Planner with maps - Incorporating Google Maps into an Australian Journey Planner | Automate Qt and QWidgets | Brisbane City Council Event Viewer - See what's going on in Brisbane, Australia

Share this post


Link to post
Share on other sites

Also in response to the combo/text box question. How are you able to tell that it's a combo box? When I do a hit test it comes back with ctxt. I know there's alittle circle beside the box and if I click on that there's about 10 different options I can double click on, which will fill in the text of the related network status profile. I guess this may be just one of those objects that act like one or the other.

Yeah it's wierd that your hit test gives you a different control ID to what I get. How can two SAP clients give different results? Mine definitely gives a control ID that includes the text "cmb" which tells me it's a combo box.


Cheers, Sean.

See my other UDFs:

Chrome UDF - Automate Chrome | SAP UDF - Automate SAP | Java UDF - Automate Java Applications & Applets | Tesseract (OCR) UDF - Capture text from applications, controls and the desktop | Textract (OCR) UDF - Capture text from applications and controls | FileSystemMonitor UDF - File, Folder, Drive and Shell Monitoring | VLC (Media Player) UDF - Creating and controlling a VLC control in AutoIT | Google Maps UDF - Creating and controlling Google Maps (inc. GE) in AutoIT | SAPIListBox (Speech Recognition) UDF - Speech Recognition via the Microsoft Speech (SAPI) ListBox | eBay UDF - Automate eBay using the eBay API | ChildProc (Parallel Processing) UDF - Parallel processing functions for AutoIT | HyperCam (Screen Recording) UDF - Automate the HyperCam screen recorder | Twitter UDF - Automate Twitter using OAuth and the Twitter API | cURL UDF - a UDF for transferring data with URL syntax

See my other Tools:

Rapid Menu Writer - Add menus to DVDs in seconds | TV Player - Automates the process of playing videos on an external TV / Monitor | Rapid Video Converter - A tool for resizing and reformatting videos | [topic130531]Rapid DVD Creator - Convert videos to DVD fast and for free | ZapPF - A tool for killing processes and recycling files | Sean's eBay Bargain Hunter - Find last minute bargains in eBay using AutoIT | Sean's GUI Inspector - A scripting tool for querying GUIs | TransLink Journey Planner with maps - Incorporating Google Maps into an Australian Journey Planner | Automate Qt and QWidgets | Brisbane City Council Event Viewer - See what's going on in Brisbane, Australia

Share this post


Link to post
Share on other sites

Yeah it's wierd that your hit test gives you a different control ID to what I get. How can two SAP clients give different results? Mine definitely gives a control ID that includes the text "cmb" which tells me it's a combo box.

Probably the difference between SAP 620 and 640... The script still works regardless :)

Share this post


Link to post
Share on other sites

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

×
×
  • Create New...