SAP through COM?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
zebuddha
Posts: 12
Joined: 03 Nov 2015, 10:17

SAP through COM?

19 Dec 2016, 10:18

Hello again,

Once more it's that time of the year, and I come bearing questions for all the good (and bad) boys and girls out there.

Ii this case, basically, I was wondering if anyone could confirm whether or not it's possible to use the COM interface to work with SAP. if so:
- Is anyone familiar with it? How do I create the COM object?
- Could anyone point me to resources regarding this? (something like the MS Excel Object Model Reference libraries)

I've been looking around but information seems pretty scarce (or I just don't know where to look)... so any help would be appreciated.

Thanks in advance.
phaleth
Posts: 38
Joined: 13 Apr 2015, 03:49

Re: SAP through COM?

19 Dec 2016, 13:15

hi,

There are few examples on how to automate SAP via COM using AutoIt over the internet.

I tried to learn COM for SAP exactly year ago. What got me back then is that I was told by our SAP admins that they aren't gonna enable SAP GUI Scripting.

After exactly one year I'm gonna fight back.
zebuddha
Posts: 12
Joined: 03 Nov 2015, 10:17

Re: SAP through COM?

20 Dec 2016, 09:54

Hmm... ok, so I confirmed that GUI Scripting is enabled, so that shouldn't be a problem. So know of any resources for this? Even if it's for VB or something, I think I can manage to translate it (more or less) ;)
phaleth
Posts: 38
Joined: 13 Apr 2015, 03:49

Re: SAP through COM?

20 Dec 2016, 11:54

Cool. Good for you that your company doesn't have the kind of we-know-it-all-best admins.

Try to rewrite and run this example.

Code: Select all

Opt("WinTitleMatchMode", 2)
WinWaitActive("SAP Easy Access")

;>>>>>>>>Session attachment>>>>>>>>>>>>>>>>>>>>>>>>>>>>
$SapGuiAuto  = ObjGet("SAPGUI")
$application = $SapGuiAuto.GetScriptingEngine
$connection  = $application.Children(0)
$session     = $connection.Children(0)
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

$session.findById("wnd[0]/tbar[0]/okcd").text = "FD32"
$session.findById("wnd[0]").sendVKey (0)
phaleth
Posts: 38
Joined: 13 Apr 2015, 03:49

Re: SAP through COM?

09 Jan 2017, 12:47

any luck? zebuddha
Kobaltauge
Posts: 264
Joined: 09 Mar 2019, 01:52
Location: Germany
Contact:

Re: SAP through COM?

27 May 2019, 04:23

Hi @phaleth
I'd tried your script. But it doesn't work.

Code: Select all

#if WinActive("SAP Easy Access")

;>>>>>>>>Session attachment>>>>>>>>>>>>>>>>>>>>>>>>>>>>
$SapGuiAuto  = ObjGet("SAPGUI")
$application = $SapGuiAuto.GetScriptingEngine
$connection  = $application.Children(0)
$session     = $connection.Children(0)
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

$session.findById("wnd[0]/tbar[0]/okcd").text = "mm02"
$session.findById("wnd[0]").sendVKey (0)

$session.findById("wnd[0]/usr/ctxtRMMG1-MATNR").text = "DEBIECAS106"
$session.findById("wnd[0]").sendVKey (0)
phaleth
Posts: 38
Joined: 13 Apr 2015, 03:49

Re: SAP through COM?

27 May 2019, 10:57

That's a code from AutoIt.

Try something like the following while on the SAP Easy Access screen:

Code: Select all

;>>>>>>>>Session attachment>>>>>>>>>>>>>>>>>>>>>>>>>>>>
sapGui  = ComObjGet("SAPGUI")
MsgBox, 0, debugging, % isObject(sapGuiAuto) ; this should display 1
application = sapGui.GetScriptingEngine
connection  = application.Children(0)
session = connection.Children(0)
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

session.findById("wnd[0]/tbar[0]/okcd").text := "mm02"
session.findById("wnd[0]").sendVKey(0)
Last edited by phaleth on 27 May 2019, 13:08, edited 1 time in total.
Kobaltauge
Posts: 264
Joined: 09 Mar 2019, 01:52
Location: Germany
Contact:

Re: SAP through COM?

27 May 2019, 12:33

yeah! I wondered why there are "$" in front of the lines. I don't get my head around this issue. I have this little script, that helps me to get the ID of the elements.
sap_controls_check.ahk
(1.08 KiB) Downloaded 191 times
But I can't get the fields set.

Code: Select all

session.FindById("wnd[0]/tbar[0]/okcd").text = "mm02"
I think I'm a section to deep or to high. Or the ".text" doesn't work with AHK.
aifritz
Posts: 301
Joined: 29 Jul 2018, 11:30
Location: Germany

Re: SAP through COM?

27 May 2019, 12:56

Code: Select all

session.FindById("wnd[0]/tbar[0]/okcd").text := "mm02"
Some little things you must adopt, translating vba to ahk:

= must be :=

and when you record some commands with arguments they must be set into ()

Also it may be better to use "/nmm02"
phaleth
Posts: 38
Joined: 13 Apr 2015, 03:49

Re: SAP through COM?

27 May 2019, 13:07

Yep, the assignment operator i used is wrong for sure.

Hard to do any coding at all without being able to test. I should try fixing my post.

Btw, the dollar signs in front of vars might still work for ahk, that wasn't the issue anyway.
Kobaltauge
Posts: 264
Joined: 09 Mar 2019, 01:52
Location: Germany
Contact:

Re: SAP through COM?

28 May 2019, 03:16

Days ago I tried with the ":=" as assignment. It didn't work. So I thought, that "=" was the right way. But both don't work.
I'll try the next days. If I found a solution, I'll post it.
User avatar
WalkerOfTheDay
Posts: 710
Joined: 24 Mar 2016, 03:01

Re: SAP through COM?

28 May 2019, 04:21

Would be interesting to know if it is really possible indeed.

We use SAP Business One at work, and I have written several scripts for it, but unfortunately have had
to use a lot of ImageSearches, PixelSearches and such...
Kobaltauge
Posts: 264
Joined: 09 Mar 2019, 01:52
Location: Germany
Contact:

Re: SAP through COM?

28 May 2019, 05:01

Got it. A lunch break is very inspiring. =)
This works. To find the "path" of the element you can use the sap_controls_check.ahk from a few posts ago.

Code: Select all

SetTitleMatchMode, 2
WinWaitActive, SAP Easy Access

;>>>>>>>>>>>>>>>>>>>>>>>>>>
_oSAP := ComObjGet("SAPGUI").GetScriptingEngine  ; Get the Already Running Instance 
Session := _oSAP.ActiveSession 
;>>>>>>>>>>>>>>>>>>>>>>>>>>

session.FindById("wnd[0]/tbar[0]/okcd").text := "/nmm03"
session.FindById("wnd[0]").sendVKey(0)

Sleep, 1000

session.findById("/app/con[0]/ses[0]/wnd[0]/usr/ctxtRMMG1-MATNR").text := "DEBIECAS106"
session.findById("wnd[0]").sendVKey(0)
phaleth
Posts: 38
Joined: 13 Apr 2015, 03:49

Re: SAP through COM?

28 May 2019, 09:09

Great, I imagine the MsgBox in the code i posted above spoiled it for you.

MsgBoxes is what you might wanna avoid when dealing with references to apps external to ahk.
aifritz
Posts: 301
Joined: 29 Jul 2018, 11:30
Location: Germany

Re: SAP through COM?

28 May 2019, 14:02

SAP Gui Scripting works quite wonderful :D
here a perhaps helpful link for recording a script:
https://blogs.sap.com/2014/08/04/script-recording-playback-for-dummies/
Kobaltauge
Posts: 264
Joined: 09 Mar 2019, 01:52
Location: Germany
Contact:

Re: SAP through COM?

29 May 2019, 02:39

aifritz wrote:
28 May 2019, 14:02
SAP Gui Scripting works quite wonderful :D
here a perhaps helpful link for recording a script:
https://blogs.sap.com/2014/08/04/script-recording-playback-for-dummies/
Yeah. Found this blog post too. It helps a lot! Thank you.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot], Marium0505, mcl and 347 guests