cancel
Showing results for 
Search instead for 
Did you mean: 

Extract text from shell container

0 Kudos

Hello,

I am really struggling to get the text out of shell container in SAP. I found some suggestions in these forums, but couldn't make it work.

Here's the sample code (sorry for the lack of syntax highlight, no insert VB option). When I use script recorder I get data displayed in hex (see bottom line in bold). Can someone help amend below code to capture text in the picture below? Transaction used: MD04

It also would be good to know how to write data as well, but that is optional.

Thank you

Sub Sourcing_open_MD04() 'lookup text

On Error GoTo ErrHandler:

Call Open_SAP

Session.findById("wnd[0]").maximize

'### transaction variables

Dim MD_Plant

Dim title

Dim sbar

Dim MessageType

MD_Plant = "TS01"

MD_Sourcing_material = Worksheets("Sourcing").Range("Sourcing_selected_material").Value

Session.findById("wnd[0]").maximize

'#### Enter info into transaction

Session.findById("wnd[0]/tbar[0]/okcd").text = "/nMD04"

Session.findById("wnd[0]").sendVKey 0

Session.findById("wnd[0]/usr/tabsTAB300/tabpF01/ssubINCLUDE300:SAPMM61R:0301/ctxtRM61R-MATNR").text = MD_Sourcing_material

Session.findById("wnd[0]/usr/tabsTAB300/tabpF01/ssubINCLUDE300:SAPMM61R:0301/ctxtRM61R-BERID").text = MD_Plant 'MRP

Session.findById("wnd[0]/usr/tabsTAB300/tabpF01/ssubINCLUDE300:SAPMM61R:0301/ctxtRM61R-WERKS").text = MD_Plant 'Plant.

Session.findById("wnd[0]").sendVKey 0 'enter

title = Session.findById("wnd[0]/titl").text

sbar = Session.findById("wnd[0]/sbar").text

MessageType = Session.findById("wnd[0]/sbar").MessageType

If MessageType = "E" Then

    MsgBox ("Can't enter transaction: " & sbar & vbCrLf & vbCrLf & "Scrip will exit")

    Exit Sub

End If

Session.findById("wnd[0]/usr/subINCLUDE8XX:SAPMM61R:0800/btnRM61R-MNTXT").press

Session.findById("wnd[0]/usr/cntlSCMSW_CONTAINER_2102/shellcont/shell").setDocument 1, "e1xydGYxXGFkZWZsYW..." 'very long value

Exit Sub

ErrHandler:

    MsgBox "Opps, something went wrong. Script will exit"

    End

End Sub

Accepted Solutions (0)

Answers (2)

Answers (2)

stefan_schnell
Active Contributor
0 Kudos

Hello Gediminas,

as far as I know has the SAPEditor control no interface to the SAP GUI Scripting API, so it is not possible to get the text via SAP GUI Scripting. The SAPEditor has the ID sapeditor.sapeditorctrl.1. Your workaround seems to be a good way to get the text via SAP GUI Scripting API. Or otherwise the way which Holger describes.

Cheers

Stefan

0 Kudos

Still looking for an answer. One workaround I found was to "change editor" from the menu to get text in a table that I can navigate through. It would be still good to know if there's solution to take text from shell.

holger_khn
Contributor
0 Kudos

Hello.

Best Option for this purpose is using functionmodule RFC_READ_TEXT via Excel VBA by using Scripting API. If you use search you should find many examples how to use.