04-26-2010 4:22 PM
Hi,
Does anyone know how to read from an SAP screen using VBA code? I am NOT referring to reading from a table like VBAK, MARA etc.
The requirement is to enter a transaction code lets say VA03/VA43, enter a document/order number and read the contents of the screen using the screen field name like VBELN, KUNNR etc.
Regards
04-26-2010 5:19 PM
In SAP transactions, the data elements appearing on the screen are in structures or table controls usually. So, while we don't do screen-scraping, code that obtains the data values from the screen structures is possible, often in exits.
04-27-2010 2:17 PM
Using vbs:
If Not IsObject(application) Then
Set SapGuiAuto = GetObject("SAPGUI")
Set application = SapGuiAuto.GetScriptingEngine
End If
If Not IsObject(connection) Then
Set connection = application.Children(0)
End If
If Not IsObject(session) Then
Set session = connection.Children(0)
End If
If IsObject(WScript) Then
WScript.ConnectObject session, "on"
WScript.ConnectObject application, "on"
End If
session.findById("wnd[0]").maximize
session.findById("wnd[0]/tbar[0]/okcd").text = "VA03"
session.findById("wnd[0]/tbar[0]/btn[0]").press
session.findById("wnd[0]/usr/ctxtSOMEFIELDNAME").text = some_variable_you_can_store_later
etc, etc
I am not familiar with tath screen so you might need more code in wnd[0]/usr/ctxtSOMEFIELDNAME if there are multiple tabs.
It will be a lot easier to make SAP record the script: ALT+F12 -> "Script Recording and Playback", etc then go to the file which is saved in your local SAP directory and see what SAP did.
Hope this helps
04-27-2010 2:22 PM
Thanks Mario. I have reasonable knowledge to use the scripting method to extract data from SAP. The trouble is that most of our SAP instances do not have SAP scripting enabled. This makes it impossible to implement a scripting based automation solution.
I am looking for a way to call a function module that will do this for me, like TxShuttle does.
04-27-2010 2:45 PM
OK
I just realised I made a mistake on a line above, I meant to say:
some_variable_you_can_store_later = session.findById("wnd[0]/usr/ctxtSOMEFIELDNAME").text
(I had flipped the order)
When I first started writing these I had scripting disabled. So I went to ALT+F12 -> Scripting and then enabled it.
Unless even that option is not there for some higher level security setting.
Good luck.