Jump to content

Help with COM object in SAP


Recommended Posts

I am new to COM objects but think I have a general idea of what is required, however, SAP has me stumped (I've read the docs on this site and others).

As of right now I can't even do the basic task of getting the attention of the SAP Script Engine. I do have a vbs script as an example that does work so here is what I have so far:

vbs:

Set SapGuiAuto = GetObject("SAPGUI")

Set application = SapGuiAuto.GetScriptingEngine

my AutoIt conversion:

$SapGuiAuto = ObjGet("","SAPGUI")

$application=$SapGuiAuto.GetScriptingEngine

When I run the vbs I get a SAP warning box from the SAP GUI saying that a script wants to run. This is what should happen.

When I run the AutoIt I get an AutoIt Error box with the follow:

$application=$SapGuiAuto.GetScriptingEngine

$application=$SapGuiAuto^ERROR

Error: Variable must be of type "Object"

In my very limited understanding it looks like vbs is able to find the SAPGUI COM object but AutoIt can't. I have ran the error trap on the AutoIt code and as far as AutoIt is concerned it is not an object.

I would applicate any help pointing me in the right direction.

Link to comment
Share on other sites

It is possible that SAPGUI does not support the IDispatch interface. Please read the Obj/COM Reference section in the helpfile. In particular, work through the OLE/COM Object Viewer to investigate SAPGUI to see if IDispatch is available.

Dale

Edit: BTW, your syntax conversion to AutoIt looks correct. Also, for grins I would try $SapGuiAuto = ObjCreate("SAPGUI") to see if it created an abject, but I would not expect it to.

Edited by DaleHohm

Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y

Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Link to comment
Share on other sites

It is possible that SAPGUI does not support the IDispatch interface. Please read the Obj/COM Reference section in the helpfile. In particular, work through the OLE/COM Object Viewer to investigate SAPGUI to see if IDispatch is available.

Thanks Dale.

OK,

I there are tons of SAP Objects in the OLE viewer so when I went to look at this the first time I could never find it. I did a text search on GetScriptingEngine in the SAP directory and found that it is in sapfewse.ocx aka SAP Scripting Control in the OLE viewer.

The program ID is Sapgui.ScriptingCtrl.1 which was not what I was looking for the first time around.

The point of all of this is that Sapgui.ScriptingCtrl.1 does not have a VersionIndependentProgID so I'm dead in the water with AutoIt v3 (get to learn some vbs).

For posterity sake, I'm using 6.2 of the SAP GUI. I know that sapfewse.ocx was updated with 6.4 of the SAP GUI so while it seems AutoIt does not work with 6.2 I don't know about 6.4.

Link to comment
Share on other sites

Does Sapgui.ScriptingCtrl.1 expose IDispatch? You are not forced to use the VersionIndependentProgID.

Dale

Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y

Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Link to comment
Share on other sites

Yes it does. You are making me think that there is hope.

Try
$SapGuiAuto = ObjGet("","Sapgui.ScriptingCtrl.1") 
$application=$SapGuiAuto.GetScriptingEngine

Dale

Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y

Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Link to comment
Share on other sites

Try

$SapGuiAuto = ObjGet("","Sapgui.ScriptingCtrl.1") 
$application=$SapGuiAuto.GetScriptingEngine
It didn't work. I also tried ObjCreate for fun and that did not work either.

If it helps, I tried this vbs (remember I don't know vbs so I don't know if the syntax is right):

Set SapGuiAuto = GetObject("Sapgui.ScriptingCtrl.1")

Set application = SapGuiAuto.GetScriptingEngine

That did not work either.

Link to comment
Share on other sites

It didn't work. I also tried ObjCreate for fun and that did not work either.

If it helps, I tried this vbs (remember I don't know vbs so I don't know if the syntax is right):

Set SapGuiAuto = GetObject("Sapgui.ScriptingCtrl.1")

Set application = SapGuiAuto.GetScriptingEngine

That did not work either.

Quick search found this: https://forums.sdn.sap.com/thread.jspa?mess...173&#536173

It suggests the following VBS syntax:

Set Wrp = CreateObject ("SapROTWr.SapROTWrapper")
Set SapGui = Wrp.GetROTEntry ("SAPGUI")
Set application = sapgui.GetScriptingEngine

ROT is the Running Object Table and is where active COM objects are registered.

The AutoIt syntax for this would be:

$Wrp = ObjCreate("SapROTWr.SapROTWrapper")
$SapGui = $Wrp.GetROTEntry ("SAPGUI")
$application = $SapGui.GetScriptingEngine

There is also a pointer in that Forum to a detailed programming document...

Dale

Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y

Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Link to comment
Share on other sites

OK Dale,

Talk about going above and beyond.

This works in SAP GUI 6.40 but not 6.20 (I just got done upgrading).

Now I can make SAP bend to the will of Autoit :)

Thanks again for all of your help. I hope one day I can give back.

Tb

Cool, glad it worked.

Dale

Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y

Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Link to comment
Share on other sites

  • 1 year later...

Hi,

:) I know that it is an old thread, but I'll give a try:

this is not working for me

$Wrp = ObjCreate("SapROTWr.SapROTWrapper")
$SapGui = $Wrp.GetROTEntry ("SAPGUI")
$application = $SapGui.GetScriptingEngine

My AutoIt version is 3.2.13.0

I'm using SAP Logon 710 and i added my .exe in the SAP Konfiguration.

Thank you for the help in advance

dworldI'm new in autoit, but I like it. My mind is open to the new things.

Link to comment
Share on other sites

  • 1 month later...
  • 2 months later...

$application=$SapGuiAuto.GetScriptingEngine

$application=$SapGuiAuto^ERROR

Error: Variable must be of type "Object"

Yes I get this error when I try to run my SAP scripts from home, because my home computer does not have the SAP GUI client installed.

At work, these commands work because that computer has SAP GUI Release 6.40 installed, and at installation time the SAP Scripting COM object is registered with Windows ( a requirement to get those statements to work).

Make sure you have the SAP GUI client installed on your computer.

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
Link to comment
Share on other sites

  • 14 years later...

Hello, a long time has passed, but as I found this thread someone else will so ... here is what I am using:

 

$SAPROT = ObjCreate("SapROTWr.SAPROTWrapper")
$GuiAuto = $SAPROT.GetROTEntry("SAPGUI")
$application = $GuiAuto.GetScriptingEngine()
$connection = $application.Children(0)
$session = $connection.children(0)

So, here is an explanation (please correct me if I was wrong):

- Create the object from the library (registered DLL):

$SAPROT = ObjCreate("SapROTWr.SAPROTWrapper")

- Here, we will connect to the "SAP Login" or "SAP Login Pad":

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

- I guess, make a connection to the SAP GUI Scripting engine:

$application = $GuiAuto.GetScriptingEngine()

- This is a connection to the server, if you have several OPENED, then you can choose the correct one:

$connection = $application.Children(0)

- And finally, make a connection to the session (windows) from that connection, max 6 sessions per connection:

$session = $connection.children(0)

 

Hope this helps, all of those are OBJECTS, so something like:

If Not IsObj($SAPROT) Then

should be used.

 

Hope this helps

 

Link to comment
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
 Share

  • Recently Browsing   0 members

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