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