I am trying to automate entering text into VA01 from Excel, to enter multiple sales orders. Mostly, it's going pretty well, but one issue I am having is that one of the operations involves adding header text (Transport details, specifically). The procedure is "Goto" -> "Header" -> "Texts", then scroll through the list on the left until I find "Transport Details", enter the text in the window on the right, then either press back or save. Using VBA and scrip recording I was able to select the correct menu item, but when I try to enter the text in the Transport Details, it instead enters the text in the top-most option which is "Billing Header Note". Obviously, that won't do.
The relevant code is as follows (I use 'with session' to avoid typing any more than I have to, because I am lazy!):
.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_HEAD/tabpT\10/ssubSUBSCREEN_BODY:SAPMV45A:4152/subSUBSCREEN_TEXT:SAPLV70T:2100/cntlSPLITTER_CONTAINER/shellcont/shellcont/shell/shellcont[0]/shell").topNode = "ZH02"
.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_HEAD/tabpT\10/ssubSUBSCREEN_BODY:SAPMV45A:4152/subSUBSCREEN_TEXT:SAPLV70T:2100/cntlSPLITTER_CONTAINER/shellcont/shellcont/shell/shellcont[0]/shell").doubleClickItem "ZTDT", "Column1"
.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_HEAD/tabpT\10/ssubSUBSCREEN_BODY:SAPMV45A:4152/subSUBSCREEN_TEXT:SAPLV70T:2100/cntlSPLITTER_CONTAINER/shellcont/shellcont/shell/shellcont[1]/shell").Text = transDets
Does anyone have any idea how to reference the correct field/text box? If any other information is needed please let me know. Any help would be greatly appreciated. I've been looking for an answer for over a week now. Also, if anyone knows where to get a decent tutorial for some of the intricacies of SAP GUI Scripting, I would be forever grateful!
SAP GUI 8.0 Scripting recorder gives the below code when I double-click 3 different text types (Z01 to Z03) and I enter different texts. It works fine for me. I adapted it to be more legible:
Dim GuiTreePath
Dim GuiTextEditPath
GuiTreePath = "wnd[0]/usr/tabsTAXI_TABSTRIP_HEAD/tabpT\10/ssubSUBSCREEN_BODY:SAPMV45A:4152" _
& "/subSUBSCREEN_TEXT:SAPLV70T:2100/cntlSPLITTER_CONTAINER/shellcont/shellcont/shell/shellcont[0]/shell"
GuiTextEditPath = "wnd[0]/usr/tabsTAXI_TABSTRIP_HEAD/tabpT\10/ssubSUBSCREEN_BODY:SAPMV45A:4152" _
& "/subSUBSCREEN_TEXT:SAPLV70T:2100/cntlSPLITTER_CONTAINER/shellcont/shellcont/shell/shellcont[1]/shell"
session.findById(GuiTreePath).selectItem "Z01","Column1"
session.findById(GuiTreePath).ensureVisibleHorizontalItem "Z01","Column1"
session.findById(GuiTreePath).doubleClickItem "Z01","Column1"
session.findById(GuiTextEditPath).text = "text for Z01" + vbCr + ""
session.findById(GuiTextEditPath).setSelectionIndexes 12,12
session.findById(GuiTreePath).selectItem "Z02","Column1"
session.findById(GuiTreePath).ensureVisibleHorizontalItem "Z02","Column1"
session.findById(GuiTreePath).doubleClickItem "Z02","Column1"
session.findById(GuiTextEditPath).text = "text for Z02" + vbCr + ""
session.findById(GuiTextEditPath).setSelectionIndexes 12,12
session.findById(GuiTreePath).selectItem "Z03","Column1"
session.findById(GuiTreePath).ensureVisibleHorizontalItem "Z03","Column1"
session.findById(GuiTreePath).doubleClickItem "Z03","Column1"
session.findById(GuiTextEditPath).text = "text for Z03" + vbCr + ""
session.findById(GuiTextEditPath).setSelectionIndexes 0,0
Your script doesn't work because you don't use selectItem
.
selectItem
is mandatory for the transaction codes VA01
/VA02
because when the user double-clicks a line from the left tree, they are considering the "currently selected item" instead of just the "double-clicked item".
When a user double clicks, it always corresponds to the two actions "mouse click" (select) and "mouse double-click" altogether, while it's two separate actions for SAP GUI Scripting.
Note that some other transaction codes might consider only the "double-clicked item" and in that case selectItem
is not needed.
It's impossible to know in advance, so to avoid any risk always do:
selectItem
doubleClickItem
selectNode
doubleClickNode
NB: for information, the methods ensureVisibleHorizontalItem
and setSelectionIndexes
are optional in the case of VA01
/VA02
.
For reference, this is the screen of VA02
(same as VA01
), with a GuiTree object on the left and a GuiTextEdit on the right: