0

I just started learning SAP GUI Scripting and cannot figure out why my macro is not recorded properly.

  1. I tried to record all the steps for a transaction at once. But every time I do it, a script contains only the part up until the line where a transaction is run. The rest of the steps are not recorded.

  2. I decided to record two parts separately and combine them manually. But it still does not work.

The macro only runs "/oCS15" transaction, it then stops and returns the error message:

the control could not be found by id. Line 20, Char 1

Can anyone advise how to fix a problem? I really hope to move on with this part of the project and assume it is just a minor issue. Please help!

I have the following script:

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 = "/oCS15"
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/usr/chkRC29L-DIRKT").selected = true
session.findById("wnd[0]/usr/ctxtRC29L-MATNR").text = "EDG001001008"
session.findById("wnd[0]/usr/chkRC29L-DIRKT").setFocus
session.findById("wnd[0]").sendVKey 5
session.findById("wnd[0]/usr/ctxtRC29L-WERKS").text = "0600"
session.findById("wnd[0]/usr/ctxtRC29L-WERKS").setFocus
session.findById("wnd[0]/usr/ctxtRC29L-WERKS").caretPosition = 4
session.findById("wnd[0]").sendVKey 8
session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell/shellcont[1]/shell").currentCellColumn = "DOBJT"
session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell/shellcont[1]/shell").selectedRows = "0"
session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell/shellcont[1]/shell").doubleClickCurrentCell
session.findById("wnd[0]/usr/tabsTS_ITEM/tabpPHPT/ssubSUBPAGE:SAPLCSDI:0830/btnP_BEZIEHUNG").press
session.findById("wnd[0]/usr/cntlSOURCE/shellcont/shell").setSelectionIndexes 0,28
Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
OAltyn
  • 21
  • 8
  • It is this line: session.findById("wnd[0]").sendVKey 0 or this line:session.findById("wnd[0]/usr/chkRC29L-DIRKT").selected = true , I think the macro recorder is leading you astray the selected, set text, setFocus are operating on different objects -MATNR vs -DIRKT, your next example does not do the same – Wookies-Will-Code Aug 21 '18 at 20:01
  • so, what shall I do with these lines? I am totally new to coding. – OAltyn Aug 21 '18 at 20:08
  • @Wookies-Will-Code I changed the code but it does not work – OAltyn Aug 21 '18 at 21:14
  • 'session.findById("wnd[0]/usr/chkRC29L-DIRKT").selected = true session.findById("wnd[0]/usr/chkRC29L-DIRKT").setFocus session.findById("wnd[0]/usr/ctxtRC29L-MATNR").text = "EDG001001008" session.findById("wnd[0]/usr/ctxtRC29L-MATNR").setFocus' – OAltyn Aug 21 '18 at 21:15
  • @Wookies-Will-Code do you have any idea why SAP recorder does not record the steps after /oCS15 step? I tried to record the whole process but it only records the first 2 steps. – OAltyn Aug 21 '18 at 21:19

1 Answers1

0

I suspect that the issue lies in starting a transaction. The command "/o" before the transaction opens a new session at the same time.

Set session = connection.Children(0) => It does not apply anymore.

Set session = connection.Children(1) => If only one session was active before, this is the new session.

But you do not necessarily have to create a new session when starting a transaction. Run the new transaction as follows:

...
session.findById("wnd[0]").maximize
session.findById("wnd[0]/tbar[0]/okcd").text = "/nCS15"
session.findById("wnd[0]").sendVKey 0
...

The script recorder records only commands within a session. If you leave them (see "/o"), the recording stops at this point.

Regards, ScriptMan

ScriptMan
  • 1,580
  • 1
  • 9
  • 9