I want to open quotation of a supplier with number "175315
" in ME49 transaction, by positioning the cursor on its number (in row 3
) and by double-clicking or pressing the F2 key on keyboard.
When I check technical info of "175315
" or "138992
", it shows EKKO-LIFNR
as screen field, LIFNR
as field name and EKKO
as table:
I tried recording SAP GUI script, but it'll record position of the field I click, like wnd[0] /usr/lbl[77,3]
. The position will be different every time, but row will be same i.e. 3
.
Below is the VBScript recorded by SAP
If Not IsObject(SapGuiAuto) Then
Set SapGuiAuto = GetObject("SAPGUI")
End If
If Not IsObject(application) Then
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
session.findById("wnd[0]").maximize
session.findById("wnd[0]/tbar[0]/okcd").text = "me49"
session.findById("wnd[0]/usr/ctxtP_EKORG").text = "e002"
session.findById("wnd[0]/usr/ctxtP_EBELN-LOW").text = "21981156"
session.findById("wnd[0]/usr/ctxtP_EBELN-LOW").setFocus
session.findById("wnd[0]/usr/ctxtP_EBELN-LOW").caretPosition = 8
session.findById("wnd[0]").sendVKey 8
session.findById("wnd[0]/usr/lbl[73,3]").setFocus
session.findById("wnd[0]/usr/lbl[73,3]").caretPosition = 4
session.findById("wnd[0]").sendVKey 2
I tried the below code, but it gives Run-Time error 619
If session.findById("wnd[0]/usr/txtEKKO-LIFNR").Text = "175315" Then
session.findById("wnd[0]/usr/txtEKKO-LIFNR").SetFocus
session.findById("wnd[0]").sendVKey 2
End If
EDIT- Found solution, but when I try to step into manually using F8, do while loop never stops even if AnfrageNr = 175315. When I run it directly, it opens the quotation of 175315. Please suggest efficient solution or other method.
On Error Resume Next
Dim i As Integer
If Not IsObject(ApplicationGUI) Then
Set SapGuiAuto = GetObject("SAPGUI")
Set ApplicationGUI = SapGuiAuto.GetScriptingEngine
End If
If Not IsObject(Connection) Then
Set Connection = ApplicationGUI.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 ApplicationGUI, "on"
End If
session.findById("wnd[0]").maximize
session.findById("wnd[0]/tbar[0]/okcd").Text = "/nme49"
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/usr/ctxtP_EKORG").Text = "E002"
session.findById("wnd[0]/usr/ctxtP_EBELN-LOW").Text = "21983729"
session.findById("wnd[0]/usr/ctxtP_EBELN-LOW").SetFocus
session.findById("wnd[0]/usr/ctxtP_EBELN-LOW").caretPosition = 8
session.findById("wnd[0]").sendVKey 8
For i = 1 To 199
Do While AnfrageNr <> 175315
AnfrageNr = session.findById("wnd[0]/usr/lbl[" & i & ",3]").Text
i = i 1
session.findById("wnd[0]/usr/lbl[" & i & ",3]").SetFocus
Loop
Next i
session.findById("wnd[0]/usr/lbl[" & i & ",3]").SetFocus
session.findById("wnd[0]").sendVKey 2
MsgBox "result:" & AnfrageNr
CodePudding user response:
First of all, you need to know that an ABAP List is not like a general screen. An ABAP List has fields which are not identified by their field names but by their positions, the Technical Information is of no help.
Visually speaking, this is an ABAP List (monospaced font only):
And this is a general screen (labels using proportional font):
This script loops at all the fields in an ABAP List:
text = ""
For Each field In session.findById("wnd[0]/usr").Children
text = text & field.CharTop & " " & field.CharLeft & " " & field.Text & " " _
& field.Id & " " & field.Type & chr(10)
Next
msgbox text
For the ABAP List above (first screenshot), the script will show:
The loop goes from top to bottom and from left to right. You can't just look at the fields of one row, but you can stop looping after a given row:
If field.CharTop > 2 Then
Exit For
End If
Each field can be of type GuiLabel
, GuiTextField
or GuiCheckBox
, and has these common properties:
CharLeft
: horizontal position in the ABAP ListCharTop
: vertical position in the ABAP ListText
(orDisplayedText
)Id
: the field name by its positionType
: the type of object
By adapting the script above, you will be able to find the horizontal positions (CharLeft
) and numbers (Text
) of all vendors in the row 2
(CharTop = 2
), and finally you can position the cursor on the vendor you want.
In the below code, reusing yours, i
would take the value of CharLeft
(use lbl
because it's a GuiLabel
field, that would be respectively txt
and chk
for GuiTextField
and GuiCheckBox
fields):
session.findById("wnd[0]/usr/lbl[" & i & ",2]").SetFocus
session.findById("wnd[0]").sendVKey 2
But instead of field.CharLeft
, you could also use directly field
or field.Id
that you obtain during the loop.