Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

VBA automation to read from SAP

Former Member
0 Kudos

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

4 REPLIES 4

Former Member
0 Kudos

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.

Former Member
0 Kudos

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

0 Kudos

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.

0 Kudos

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.