cancel
Showing results for 
Search instead for 
Did you mean: 

Script Recording & Playback

Former Member
0 Kudos

I have been using Script Recording & Playback to output excel documents from CM01.

Everything works just fine and I have been very happy with the results.

Just the other day when I tried to play a script from the Script Recording & Playback interface..

Nothing happened.

I can still record new scripts with the interface, but when I click on the green arrow, select a file and click open, nothing happens.

(No errors and I am back to the original interface.)

If I have a SAP easy Access window open I can execute the .vbs file through Windows Explorer by double clicking on it.

Then everything works fine.

Does anyone have an idea on why this would be?

Thanks in advance.

Accepted Solutions (0)

Answers (1)

Answers (1)

script_man
Active Contributor
0 Kudos

Hi Sleepydog,

Unfortunately I have no explanation for the phenomenon. One thing is certain, however. By execute of the script from the Windows Explorer is always addressed the currently lowest SAP session. When you run the script from SAP is always addressed the straight current SAP session.

Example: Two SAP sessions are open. The following script provides two different results. The condition is that it starts from the highest SAP session.


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
msgbox session.info.sessionnumber

Regards,

ScriptMan

Former Member
0 Kudos

ScriptMan,

Are you able to help me with a code to open SAP R/3 from Excel, client; 400, user; CASTLESD, password; PASSWORD1, language; EN. Then to open transaction IW37 or custom ZQIW37_SER work centre; 554FT, early start date; Current month early finish date; Current month.

script_man
Active Contributor
0 Kudos

Hi SAPDyl,

You could use the following script:


If Not IsObject(SAPguiApp) Then
Set SAPguiApp = CreateObject("Sapgui.ScriptingCtrl.1")
End If
If Not IsObject(Connection) Then
Set Connection = SAPguiApp.OpenConnection("SYSTEM", True)
End If
If Not IsObject(Session) Then
Set Session = Connection.Children(0)
End If
Session.findById("wnd[0]/usr/txtRSYST-MANDT").Text = "400"
Session.findById("wnd[0]/usr/txtRSYST-BNAME").Text = "CASTLESD"
Session.findById("wnd[0]/usr/pwdRSYST-BCODE").Text = "PASSWORD1"
Session.findById("wnd[0]/usr/txtRSYST-LANGU").Text = "EN"
Session.findById("wnd[0]").sendVKey 0

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

'Here follows the recorded script without the first 14 rows.

As "SYSTEM" You have to use the name of your SAP - system. Please use the script recorder to record a script on ALT / F12.

Regards,

ScriptMan

Former Member
0 Kudos

Scriptman below is the code being run however error with logon, will open R/# but will not logon as user and password am i missing something? Seems to prompt for debug at session.findById("wnd[0]/usr/txtRSYST-BNAME").Text = "castlesd"

If Not IsObject(SAPguiApp) Then

Set SAPguiApp = CreateObject("Sapgui.ScriptingCtrl.1")

End If

If Not IsObject(Connection) Then

Set Connection = SAPguiApp.OpenConnection("1. SAP R/3 Production Environment", True)

End If

session.findById("wnd[0]/usr/txtRSYST-BNAME").Text = "castlesd"

session.findById("wnd[0]/usr/pwdRSYST-BCODE").Text = "password1"

session.findById("wnd[0]/usr/txtRSYST-LANGU").Text = "EN"

session.findById("wnd[0]/usr/txtRSYST-LANGU").SetFocus

session.findById("wnd[0]/usr/txtRSYST-LANGU").caretPosition = 2

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

session.findById("wnd[0]/tbar[0]/okcd").Text = "/zqiw37_ser"

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

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

MsgBox "If you click on the OK button, the SAP session is terminated."

End Sub

script_man
Active Contributor
0 Kudos

Hi SAPDyl,

It is missing in your script the following command:


. . .
Session.findById("wnd[0]/usr/txtRSYST-MANDT").Text = "400"
. . .

Regards,

ScriptMan

Former Member
0 Kudos

Hi Scriptman,

It has been a while, i am still having trouble with the below code to logon to R3, as far as i can get is to the logon, cursor flashing in the user name field. I have noticed the system and language fields are auto filled. If i remove Session.findById("wnd[0]/usr/txtRSYST-MANDT").Text = "400" still the same result in SAP and a error debug prompt at the line following the End If. Am i missing something again.

Thanks SAPDyl

If Not IsObject(SAPguiApp) Then

Set SAPguiApp = CreateObject("Sapgui.ScriptingCtrl.1";)

End If

If Not IsObject(Connection) Then

Set Connection = SAPguiApp.OpenConnection("1. SAP R/3 Production Environment", True)

End If

Session.findById("wnd[0]/usr/txtRSYST-MANDT").Text = "400"

Session.findById("wnd[0]/usr/txtRSYST-BNAME").Text = "castlesd"

Session.findById("wnd[0]/usr/pwdRSYST-BCODE").Text = "zxcvbnm"

Session.findById("wnd[0]/usr/txtRSYST-LANGU").Text = "EN"

Session.findById("wnd[0]/usr/txtRSYST-LANGU").SetFocus

Session.findById("wnd[0]/usr/txtRSYST-LANGU").caretPosition = 2

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

Session.findById("wnd[0]/tbar[0]/okcd").Text = "/zqiw37_ser"

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

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

MsgBox "If you click on the OK button, the SAP session is terminated."

End Sub

script_man
Active Contributor
0 Kudos

Hi SAPDyl,

I suspect that this time missing the following commands:


. . .
If Not IsObject(Connection) Then 
Set Connection = SAPguiApp.OpenConnection("1. SAP R/3 Production Environment", True) 
End If 
'new commands
If Not IsObject(Session) Then
Set Session = Connection.Children(0)
End If
'new commands
Session.findById("wnd[0]/usr/txtRSYST-MANDT").Text = "400" 
. . .

Regards,

ScriptMan