-3

Now I'm developing a listener tool with python and now I'm a bit confused with SAP GUI. It was easy to make an event listener for Excel with win32com.client.WithEvents(). So the same I can use to SAP GUI but I'm in need of list or examples of possible SAP GUI events. Looks like there is no appropriate documentation, but I'm sure there must be.

So how to use SAP GUI with win32? And maybe you know how to follow and listen its events?

Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
  • SAP has interfaces for RFC,  BAPI, IDoc, SOAP, and REST. But not, I think, for COM. If there were, it would certainly be documented. – BoarGules Apr 01 '21 at 09:10
  • What SAP software are you talking about? – Sandra Rossi Apr 01 '21 at 11:03
  • Do you mean the recording of user actions in SAP GUI for Windows? – Sandra Rossi Apr 05 '21 at 08:11
  • Depends what you want to do. Do you want to control the SAP GUI with python? Do you just want to get data via python? Or do you just want to build a listener / logging tool to log what people are doing inside sap? I think the last one is not possible / as easy as you think. The first one I would need to look it up, but there are ressources that explain it a little bit ( mainly because other developers who did it had the same request ). The easiest one is just getting data out of SAP. You just have to call FM "RFC_READ_TABLE". – Sasku Apr 06 '21 at 18:08
  • 1
    @SandraRossi Yes! I'm developing a tool to detect and record users activity. I have a good part of code to listen to excel events (record the activity), here what I mean https://www.linkedin.com/pulse/using-excel-events-python-alex-reed you can find an example. I know that the same package win32com.client can be used with SAP GUI Application COM object. And now I probably need to figure out my opportunity to record activity and events. – Семен Каминский Apr 07 '21 at 19:54
  • @Sasku I don't need data in SAP, I just want to record the user activity in SAP (COM object events). And I suppose that it could be natively done within pywin32, but I don't know how. – Семен Каминский Apr 07 '21 at 19:57

1 Answers1

0

To use SAP with win32com you can check the following link:

https://blogs.sap.com/2017/09/19/how-to-use-sap-gui-scripting-inside-python-programming-language/

The SAP GUI Application object can be accessed as follows:

Application = win32com.client.GetObject("SAPGUI").getScriptingEngine

From there you can use most methods / properties as indicated in the SAP GUI scripting API guide:

https://help.sap.com/doc/9215986e54174174854b0af6bb14305a/760.01/en-US/sap_gui_scripting_api_761.pdf

The SAP events are also listed in that document. However, I have not figured out how Python can listen to those events.