Script Recording & Playback for Dummies
This document will explain how to automate the execution of steps in SAP using the Script Recording and Playback.
You should be able to make your own script by following this document. It is not necessary to have programming knowledge.
You can use Script to automate business transactions, to automate master data creation, to automate configuration, etc..
Some comments about SAP Script Recording and Playback:
- This is an interface exposed by SAP GUI.
- It is a standard SAP tool and could available or disable.
- Can make life easier for users by automating repeating tasks.
1- Generate the Script (*.vbs)
The Script file can be generated automatically by recording the steps executed in SAP.
The following screenshots show how to create the main script file in a few minutes or even second:
It is important to select the file extension .vbs:
Once you press Start Recording, you will see this indicator at the bottom of the screen:
Execute the transaction that you want to save in the script. Depending on what you are trying to automate, you will need to enter the SAP tcode with /n. If you do this you will leave and you will access the t-code again in each iteration.
Enter all the fields that you are going to automate:
Once one iteration is completed, press Stop Recording. This will complete the generation of the Script and the file will be saved in the selected Path:
2- Enhance the Script (*.vbs) to allow the automation via Excel
Find and open with the Notepad the Script file generated in the previous step.
To allow the automation, it is necessary to do two things:
- Add two blocks of programming code in the vbs: There is no need to understand how to program a script. The code is always the same. The only thing that could change is the number of columns used in the excel. In this example we are going to use 5 columns.
This is the code of each block of code. If you need to add columns in the excel, you will need to add the sentence in red color:
Block of code: Block A
REM ADDED BY EXCEL *************************************
Dim objExcel
Dim objSheet, intRow, i
Set objExcel = GetObject(,”Excel.Application”)
Set objSheet = objExcel.ActiveWorkbook.ActiveSheet
For i = 2 to objSheet.UsedRange.Rows.Count
COL1 = Trim(CStr(objSheet.Cells(i, 1).Value)) ‘Column1
COL2 = Trim(CStr(objSheet.Cells(i, 2).Value)) ‘Column2
COL3 = Trim(CStr(objSheet.Cells(i, 3).Value)) ‘Column3
COL4 = Trim(CStr(objSheet.Cells(i, 4).Value)) ‘Column4
COL5 = Trim(CStr(objSheet.Cells(i, 5).Value)) ‘Column5
COL6 = Trim(CStr(objSheet.Cells(i, 6).Value)) ‘Column6
REM ADDED BY EXCEL *************************************
Block of code: Block B
REM FINALIZATION CONTROL CHECK ************************
aux=col1 & ” ” & col2 & ” ” & col3 & ” ” & col4 & ” ” & col5 & ” ” & col6
CreateObject(“WScript.Shell”).run(“cmd /c @echo %date% %time% ” & aux & ” >> C:\SCRIPT\PlOrCreationLog.txt”)
next
msgbox “Process Completed”
REM FINALIZATION CONTROL CHECK ************************
- Replace the “hardcoaded code” by the Columns#:
This is the final code of the Script (in red color the text added):
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
REM ADDED BY EXCEL *************************************
Dim objExcel
Dim objSheet, intRow, i
Set objExcel = GetObject(,”Excel.Application”)
Set objSheet = objExcel.ActiveWorkbook.ActiveSheet
For i = 2 to objSheet.UsedRange.Rows.Count
COL1 = Trim(CStr(objSheet.Cells(i, 1).Value)) ‘Column1
COL2 = Trim(CStr(objSheet.Cells(i, 2).Value)) ‘Column2
COL3 = Trim(CStr(objSheet.Cells(i, 3).Value)) ‘Column3
COL4 = Trim(CStr(objSheet.Cells(i, 4).Value)) ‘Column4
COL5 = Trim(CStr(objSheet.Cells(i, 5).Value)) ‘Column5
REM ADDED BY EXCEL *************************************
session.findById(“wnd[0]/tbar[0]/okcd”).text = “/nmd11”
session.findById(“wnd[0]”).sendVKey 0
session.findById(“wnd[0]/usr/ctxtRM61P-PASCH”).text = COL1
session.findById(“wnd[0]/usr/ctxtRM61P-PASCH”).caretPosition = 2
session.findById(“wnd[0]”).sendVKey 0
session.findById(“wnd[0]/usr/ctxtPLAF-MATNR”).text = COL2
session.findById(“wnd[0]/usr/ctxtPLAF-PLWRK”).text = COL3
session.findById(“wnd
[0]/usr/tabsTABTC/tabpTAB01/ssubINCLUDE1XX:SAPLM61O:0711/subINCLUDE711_1:SAPLM61O:0802/txtPLAF
-GSMNG”).text = COL4
session.findById(“wnd
[0]/usr/tabsTABTC/tabpTAB01/ssubINCLUDE1XX:SAPLM61O:0711/subINCLUDE711_1:SAPLM61O:0802/ctxtPLA
F-PSTTR”).text = COL5
session.findById(“wnd
[0]/usr/tabsTABTC/tabpTAB01/ssubINCLUDE1XX:SAPLM61O:0711/subINCLUDE711_1:SAPLM61O:0802/ctxtPLA
F-PSTTR”).setFocus
session.findById(“wnd
[0]/usr/tabsTABTC/tabpTAB01/ssubINCLUDE1XX:SAPLM61O:0711/subINCLUDE711_1:SAPLM61O:0802/ctxtPLA
F-PSTTR”).caretPosition = 10
session.findById(“wnd[0]”).sendVKey 0
session.findById(“wnd[0]/tbar[0]/btn[11]”).press
REM FINALIZATION CONTROL CHECK ************************
aux=col1 & ” ” & col2 & ” ” & col3 & ” ” & col4 & ” ” & col5
CreateObject(“WScript.Shell”).run(“cmd /c @echo %date% %time% ” & aux & ” >> C:\SCRIPT
\PlOrCreationLog.txt”)
next
msgbox “Process Completed”
REM FINALIZATION CONTROL CHECK ************************
3- Maintain the Excel file
Enter all the data to be used in the automation. The script will always start reading from the second line. Use the first line for the header:
Important: Only one excel file should be opened to execute the Script
4- Script Execution
Remember the previous message: Only one excel file should be opened to execute the Script
Keep your Excel file opened. Open the Script Recording and Playback toolkit, Select the path and the file and press Play…
You will see how it works!!
5- Enableling SapScript Recording and Playback
SAP Script Recording and Playback is disable by Default.
It can be enable using a profile parameter. Note 480149 describes the requirement to enable this functionality:
480149
– New profile parameter for user scripting at the front end
The sapgui/user_scripting parameter is imported again. If this parameter is
set to TRUE, the scripting functions can be used with a GUI as of
version 6.20 on the front end.
The default value of the parameter
is FALSE so that scripting to the system is not possible.
Note
that you must enter the values in upper case;
There are 2 options for
setting the parameter: In transaction rz11 and in the server profile. If the
parameter is only set in rz11, the change is lost when you restart the
server.
Setting the parameter in the SAP
system
===============================================
If possible,
dynamic setting of the parameter is executed using transaction rz11. Specify the
parameter name sapgui/user_scripting and select ‘Display’.
Provided that the
current value is set to FALSE, select the ‘Change value’ button in
the toolbar. A window now appears, in which you can enter the new value
TRUE. When you save the change, the window closes and the current value
of the parameter changes to TRUE. This change only becomes effective when
you log onto the system again.
If the parameter is not found, you must
import the relevant Support Package in accordance with the list below.
If
the current value does not change accordingly after you have saved the change,
it means that the kernel is too old. In this case, import the required kernel
patch, as specified below.
Setting the parameter in the server
profile
======================================
If you have not
imported the Support Package, you can switch the scripting on if you set the
parameter in the profile file of the application server with the following
line:
sapgui/user_scripting = TRUE
This procedure only requires the
specified kernel patch level, however, you must restart the application
server.
5- More functionalities of Sap Script Recording and Playback
There are much more functionalities that can be used. For example, you can collect the SAP messages or add conditional logic. You can read about it in the following article:
Dear Mariano Cabalen,
by using Script Recording and Playback, could you tell me if the field name in script (from views) lets us identify the name of field stored in SAP Tables ?
Otherwise, do you know a simple way to get it ?
Best
Amaury
This is pretty cool. Encountered when searching for a some other requirement.
do you know how long has this been available in SAP and from which version it is available?
It is available in v6.2 and later.
See "Availability" section here: https://wiki.scn.sap.com/wiki/display/ATopics/SAP+GUI+Scripting
Hello, these are excellent instructions but I got the dreaded "invalid character" and it turns out when you copy and paste from either Word or a web page some of the apostrophes, etc change.
I had to update the REM ADDED BY EXCEL ************************************* to add ' at the beginning and also had to update and instances of ” as in
Set objExcel = GetObject(,”Excel.Application”) to the proper character of "
http://ascii.cl/
The differences are hard to see. Luckily, when I right click on the notepad document there is an Open with option of Microsoft Windows Based Script Host and when I selected it I was provided the line and character location of the bad data.
Hey everyone. Have we found a solution to the error:
"ActiveX component can't create object: 'GetObject' -
It's disappointing as I have a very small script to run but can't launch it due to this error. I even changed the quotation marks/apostrophes as most recently recognized by Debra Miller. The script is as follows:
Dim objExcel
Dim objSheet, intRow, i
Set objExcel = GetObject(,"Excel.Application")
Set objSheet = objExcel.ActiveWorkbook.ActiveSheet
For i = 2 to objSheet.UsedRange.Rows.Count
COL1 = Trim(CStr(objSheet.Cells(i, 1).Value)) 'Column1
COL2 = Trim(CStr(objSheet.Cells(i, 2).Value)) 'Column2
COL3 = Trim(CStr(objSheet.Cells(i, 3).Value)) 'Column3
COL4 = Trim(CStr(objSheet.Cells(i, 4).Value)) 'Column4
COL5 = Trim(CStr(objSheet.Cells(i, 5).Value)) 'Column5
COL6 = Trim(CStr(objSheet.Cells(i, 6).Value)) 'Column6
REM ADDED BY EXCEL *************************************
session.findById("wnd[0]").maximize
session.findById("wnd[0]/tbar[0]/okcd").text = "zsdpas"
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/usr/ctxt[1]").text = "COL1"
session.findById("wnd[0]/usr/ctxt[1]").setFocus
session.findById("wnd[0]/usr/ctxt[1]").caretPosition = 7
session.findById("wnd[0]/tbar[1]/btn[8]").press
session.findById("wnd[0]/tbar[1]/btn[31]").press
session.findById("wnd[0]/usr/sub/1/sub/1/2/tabsTAB_CONTROL/tabpREC/ssub/1/2/1/2/tblSAPLSO04REC_CONTROL/ctxt[0,0]").text = "Xxxxx.xxxx@xxxxxx.com"
session.findById("wnd[0]/usr/sub/1/sub/1/2/tabsTAB_CONTROL/tabpREC/ssub/1/2/1/2/tblSAPLSO04REC_CONTROL/ctxt[0,0]").setFocus
session.findById("wnd[0]/usr/sub/1/sub/1/2/tabsTAB_CONTROL/tabpREC/ssub/1/2/1/2/tblSAPLSO04REC_CONTROL/ctxt[0,0]").caretPosition = 23
session.findById("wnd[0]/tbar[1]/btn[20]").press
session.findById("wnd[0]/tbar[0]/btn[3]").press
session.findById("wnd[0]/tbar[0]/btn[3]").press
REM FINALIZATION CONTROL CHECK ************************
aux=col1 & " " & col2 & " " & col3 & " " & col4 & " " & col5 & " " & col6
CreateObject("WScript.Shell").run("cmd /c @echo %date% %time% " & aux & " >> C:\SCRIPT\PlOrCreationLog.txt")
next
msgbox "Process Completed"
REM FINALIZATION CONTROL CHECK ************************
Granting this capability would immensely assist in my every day work! Thank you all in advance for your support and time!
Hi Eric,
Probably a bit late, but I had the same issue today. It was because I did not have the Excel file open. Once I opened the Excel, it worked fine.
KR
Jaap
Hello Friends,
I am getting the below error while executing my script ” The control could not be found by id”
i have pasted the script below. Can you please help.
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
Dim objExcel
Dim objSheet, intRow, i
Set objExcel = GetObject(, “Excel.Application”)
Set objSheet = objExcel.ActiveWorkbook.ActiveSheet
For i = 2 to objSheet.UsedRange.Rows.Count
COL1 = Trim(CStr(objSheet.Cells(i, 1).Value)) ‘column1
COL2 = Trim(CStr(objSheet.Cells(i, 2).Value)) ‘column2
COL3 = Trim(CStr(objSheet.Cells(i, 3).Value)) ‘column3
COL4 = Trim(CStr(objSheet.Cells(i, 4).Value)) ‘column4
COL5 = Trim(CStr(objSheet.Cells(i, 5).Value)) ‘column5
session.findById(“wnd[0]/tbar[0]/okcd”).text = “/nfpp2”
session.findById(“wnd[0]”).sendVKey 0
session.findById(“wnd[1]/usr/ctxtBUS_JOEL_MAIN-OPEN_NUMBER”).text = COL1
session.findById(“wnd[1]/usr/ctxtBUS_JOEL_MAIN-OPEN_NUMBER”).caretPosition = 10
session.findById(“wnd[1]/tbar[0]/btn[0]”).press
session.findById(“wnd[0]/usr/subSCREEN_3000_RESIZING_AREA:SAPLBUS_LOCATOR:2036/subSCREEN_1010_RIGHT_AREA:SAPLBUPA_DIALOG_JOEL:1000/ssubSCREEN_1000_WORKAREA_AREA:SAPLBUPA_DIALOG_JOEL:1100/ssubSCREEN_1100_MAIN_AREA:SAPLBUPA_DIALOG_JOEL:1101/tabsGS_SCREEN_1100_TABSTRIP/tabpSCREEN_1100_TAB_01/ssubSCREEN_1100_TABSTRIP_AREA:SAPLBUSS:0028/ssubGENSUB:SAPLBUSS:7016/subA05P01:SAPLBUA0:0400/subADDRESS:SAPLSZA1:0300/subCOUNTRY_SCREEN:SAPLSZA1:0304/ctxtADDR1_DATA-STREET”).text = “PO BOX 2440”
session.findById(“wnd[0]/usr/subSCREEN_3000_RESIZING_AREA:SAPLBUS_LOCATOR:2036/subSCREEN_1010_RIGHT_AREA:SAPLBUPA_DIALOG_JOEL:1000/ssubSCREEN_1000_WORKAREA_AREA:SAPLBUPA_DIALOG_JOEL:1100/ssubSCREEN_1100_MAIN_AREA:SAPLBUPA_DIALOG_JOEL:1101/tabsGS_SCREEN_1100_TABSTRIP/tabpSCREEN_1100_TAB_01/ssubSCREEN_1100_TABSTRIP_AREA:SAPLBUSS:0028/ssubGENSUB:SAPLBUSS:7016/subA05P01:SAPLBUA0:0400/subADDRESS:SAPLSZA1:0300/subCOUNTRY_SCREEN:SAPLSZA1:0304/ctxtADDR1_DATA-CITY1”).text = “SPOKANE”
session.findById(“wnd[0]/usr/subSCREEN_3000_RESIZING_AREA:SAPLBUS_LOCATOR:2036/subSCREEN_1010_RIGHT_AREA:SAPLBUPA_DIALOG_JOEL:1000/ssubSCREEN_1000_WORKAREA_AREA:SAPLBUPA_DIALOG_JOEL:1100/ssubSCREEN_1100_MAIN_AREA:SAPLBUPA_DIALOG_JOEL:1101/tabsGS_SCREEN_1100_TABSTRIP/tabpSCREEN_1100_TAB_01/ssubSCREEN_1100_TABSTRIP_AREA:SAPLBUSS:0028/ssubGENSUB:SAPLBUSS:7016/subA05P01:SAPLBUA0:0400/subADDRESS:SAPLSZA1:0300/subCOUNTRY_SCREEN:SAPLSZA1:0304/ctxtADDR1_DATA-REGION”).text = “WA”
session.findById(“wnd[0]/usr/subSCREEN_3000_RESIZING_AREA:SAPLBUS_LOCATOR:2036/subSCREEN_1010_RIGHT_AREA:SAPLBUPA_DIALOG_JOEL:1000/ssubSCREEN_1000_WORKAREA_AREA:SAPLBUPA_DIALOG_JOEL:1100/ssubSCREEN_1100_MAIN_AREA:SAPLBUPA_DIALOG_JOEL:1101/tabsGS_SCREEN_1100_TABSTRIP/tabpSCREEN_1100_TAB_01/ssubSCREEN_1100_TABSTRIP_AREA:SAPLBUSS:0028/ssubGENSUB:SAPLBUSS:7016/subA05P01:SAPLBUA0:0400/subADDRESS:SAPLSZA1:0300/subCOUNTRY_SCREEN:SAPLSZA1:0304/txtADDR1_DATA-POST_CODE1”).text = “99210-2440”
session.findById(“wnd[0]/usr/subSCREEN_3000_RESIZING_AREA:SAPLBUS_LOCATOR:2036/subSCREEN_1010_RIGHT_AREA:SAPLBUPA_DIALOG_JOEL:1000/ssubSCREEN_1000_WORKAREA_AREA:SAPLBUPA_DIALOG_JOEL:1100/ssubSCREEN_1100_MAIN_AREA:SAPLBUPA_DIALOG_JOEL:1101/tabsGS_SCREEN_1100_TABSTRIP/tabpSCREEN_1100_TAB_01/ssubSCREEN_1100_TABSTRIP_AREA:SAPLBUSS:0028/ssubGENSUB:SAPLBUSS:7016/subA05P01:SAPLBUA0:0400/subADDRESS:SAPLSZA1:0300/subCOUNTRY_SCREEN:SAPLSZA1:0304/txtADDR1_DATA-POST_CODE1”).setFocus
session.findById(“wnd[0]/usr/subSCREEN_3000_RESIZING_AREA:SAPLBUS_LOCATOR:2036/subSCREEN_1010_RIGHT_AREA:SAPLBUPA_DIALOG_JOEL:1000/ssubSCREEN_1000_WORKAREA_AREA:SAPLBUPA_DIALOG_JOEL:1100/ssubSCREEN_1100_MAIN_AREA:SAPLBUPA_DIALOG_JOEL:1101/tabsGS_SCREEN_1100_TABSTRIP/tabpSCREEN_1100_TAB_01/ssubSCREEN_1100_TABSTRIP_AREA:SAPLBUSS:0028/ssubGENSUB:SAPLBUSS:7016/subA05P01:SAPLBUA0:0400/subADDRESS:SAPLSZA1:0300/subCOUNTRY_SCREEN:SAPLSZA1:0304/txtADDR1_DATA-POST_CODE1”).caretPosition = 2
session.findById(“wnd[0]/tbar[0]/btn[11]”).press
session.findById(“wnd[1]/tbar[0]/btn[0]”).press
aux=col1 & ” ” & col2 & ” ” & col3 & ” ” & col4 & ” ” & col5
CreateObject(“WScript.Shell”).run(“cmd /c @echo %date% %time% ” & aux & ” >> C:\SCRIPT\PlOrCreationLog.txt”)
next
msgbox “Process Completed”
Hi All, could you help me. Ive created script according the manual. Very thank you for sharing. But i have a problem:
I have script .vbs recorded on one notebook[A]. The part of code:
session.findById("wnd[0]/usr/ctxtLIKP-LIFNR").text = "103005"
On the other notebook[B] the same part looks like:
session.findById("wnd[0]/usr/ctxt[0]").text = "103005"
When i try to run scrip from the first Notebook[A] on the other [B], the second one gives message: "The control could not be found by id"
The same error i have got when run script from notebook[B] on notebook [A].
Also we have many others notebooks in company. They record scripts in the same way as the notebook [B] (session.findById("wnd[0]/usr/ctxt[0]").text)
But we have huge script recorded on the notebook [A] and we need to run it on others notebooks.
Is there any ways to make other notebooks read the script (session.findById("wnd[0]/usr/ctxtLIKP-LIFNR").text = "103005") correctly?
Thank you in advance.
Hi everybody!
This is really useful to me but I wonder if there is someway to do the oposite direction, I want to export the data from SAP to an excel file and save it, with the name and in the location that I choose, so I can work on the data using excel's Macros or something.
Thank you
Hi There
This is possible you way to do the opposite direction if you want.
Like this: Range("A"& i) = session.findById(“wnd[0]/usr/ctxt[0]”).text
In this way VBA collect information to spreadsheet.
Cheers
Flávio
Hi Mariano,
I get below error message often. However sometimes it works just fine. Seems it works just fine when there are not too much people working in SAP. I checked SAP connection under network tab and it is HIGH SPEED CONNECTION.
What I’m trying to do is to have a script for price update on PO level.
From COL1 it picks PO number from excel sheet, from COL2 it picks up price from excel sheet.
When it does not work I always get below error message (it’s the line highlighted in bold in the script below):
Line: 40
Char: 1
Error: The control could not be found by id
Code: 800A026B
————————————
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
REM ADDED BY EXCEL *************************************
Dim objExcel
Dim objSheet, intRow, i
Set objExcel = GetObject(,”Excel.Application”)
Set objSheet = objExcel.ActiveWorkbook.ActiveSheet
For i = 2 to objSheet.UsedRange.Rows.Count
COL1 = Trim(CStr(objSheet.Cells(i, 1).Value)) ‘Column1
COL2 = Trim(CStr(objSheet.Cells(i, 2).Value)) ‘Column2
REM ADDED BY EXCEL *************************************
session.findById(“wnd[0]/tbar[0]/okcd”).text = “/nme22n”
session.findById(“wnd[0]”).sendVKey 0
session.findById(“wnd[0]/tbar[1]/btn[17]”).press
session.findById(“wnd[1]/usr/subSUB0:SAPLMEGUI:0003/ctxtMEPO_SELECT-EBELN”).text = COL1
session.findById(“wnd[1]”).sendVKey 0
session.findById(“wnd[0]/usr/subSUB0:SAPLMEGUI:0010/subSUB2:SAPLMEVIEWS:1100/subSUB2:SAPLMEVIEWS:1200/subSUB1:SAPLMEGUI:1211/tblSAPLMEGUITC_1211/txtMEPO1211-NETPR[10,0]”).text = COL2
session.findById(“wnd[0]/usr/subSUB0:SAPLMEGUI:0010/subSUB2:SAPLMEVIEWS:1100/subSUB2:SAPLMEVIEWS:1200/subSUB1:SAPLMEGUI:1211/tblSAPLMEGUITC_1211/txtMEPO1211-NETPR[10,0]”).setFocus
session.findById(“wnd[0]/usr/subSUB0:SAPLMEGUI:0010/subSUB2:SAPLMEVIEWS:1100/subSUB2:SAPLMEVIEWS:1200/subSUB1:SAPLMEGUI:1211/tblSAPLMEGUITC_1211/txtMEPO1211-NETPR[10,0]”).caretPosition = 14
session.findById(“wnd[0]”).sendVKey 0
session.findById(“wnd[0]”).sendVKey 11
session.findById(“wnd[1]/usr/btnSPOP-VAROPTION1″).press
REM FINALIZATION CONTROL CHECK ************************
aux=col1 & ” ” & col2
CreateObject(“WScript.Shell”).run(“cmd /c @echo %date% %time% ” & aux & ” >> C:\SCRIPT\PlOrCreationLog.txt”)
next
msgbox “Process Completed”
REM FINALIZATION CONTROL CHECK ************************
Hi Adis Mujcinagic,
Try to replace this
session.findById(“wnd[0]/usr/subSUB0:SAPLMEGUI:0010/subSUB2:SAPLMEVIEWS:1100/subSUB2:SAPLMEVIEWS:1200/subSUB1:SAPLMEGUI:1211/tblSAPLMEGUITC_1211/txtMEPO1211-NETPR[10,0]”).text = COL2
For this
session.findById(“wnd[0]/usr/subSUB0:SAPLMEGUI:0015/subSUB2:SAPLMEVIEWS:1100/subSUB2:SAPLMEVIEWS:1200/subSUB1:SAPLMEGUI:1211/tblSAPLMEGUITC_1211/txtMEPO1211-NETPR[10,0]”).text = COL2
Pedro
Thanks for reply Pedro!
It seems the script is sensitive to which fields and sheets were displayed when script was recorded.
If you then klick on different sheets in a PO and exit the PO and then try to run the script you get error message. Nowadays when I record a script I make sure to remember which sheets were displayed. For instance Status sheet under Header and Confirmations sheet under Item Detail.
Then if I need to run a script I access one PO manually make sure that those same sheets are displayed and exit it again. Then I run the script.
Never got error message after that!
Hi Mariono,
That's some really helpful stuff you have shared 🙂
The question that i have over here is, Do we have a possibility to run this record and play macro in
multiple clusters at a time?
For Ex: I work upon 2 clusters in SAP which are GP1 & LP1 and i would like to extract data from both the clusters at one go, Can i do that?
I'm also aware of the excel to SAP connection possibility with the help of "Dim application" code
Your comments on this question would be greatly helpful for me.
Thanking you in advance!
Chandra Shekar. Y
Excellent document, instructions and helpful comments! Thanks 🙂
Hi all,
I need to grab a field from a SAP page that is not editable. If you look at a post above from Rohit Mansukh Gugale August 2, 2017 at 11:45 am I'd like to read the field that says first name and not just the field where the name is typed!
I have a application where I need to read several fields on a SAP page and can do so easily with editable fields but not the non-editable fields!
I seem to remember seeing a way to do a page dump of the variable names used!
Thanks
Pete
Is there a way to create a Favorites shortcut for a script?
You may record scripts for each functionality and save them on your PC. When trying to perform, you can drag and drop the files too for that particular activity instead of playing from the "Script recording and playback".
Hi all,
May I ask a question?
When I try to control a ALV use SAP script,such as change value in SE16N or other ALV, How can I get the count of ALV rows?
The problem is , if I try to change a value in rows 2,I should use
session.findById("...").modifyCell 1,"COL","value"
but I'm not sure the second row exists,so then will get an error. so if I can get the count of the ALV rows, it can be solved. I try many of ways,such as ' .countRows /totalRows ' as so on , but is wrong, I can't find the relevant document.
Can you help me? very thanks.
Hello Wenjie,
Are you still facing this issue?
If it still persists, please send me few snaps over write2arunesh@gmail.com or connect with me to fix it for good.
Dear Mariano Cabalen,
Thank you for an excellent article.
Could you please tell,
I have the task to update the material master data with approximately 10,000 or 15,000 entries.
This Update needs to be done in a few hours.
Now I choose a tool for this task between both LSMW and SAP GUI Scripting.
What is preferable to choose for this task?
Could you tell me what LSMW or SAP GUI Scripting will work faster?
I would be grateful for the answer.
Hello Vladimir,
I know I joined late and this post is quite old. By now you might have had your answer, but in case you haven't, be advised that SAPGUI is always preferable, reliable and faster than LSWM or SECATT scripts.
If you want more insights into SAPGUI, you may feel free to reach me at write2arunesh@gmail.com
We are in SAP 4S HANA Migration -
"We created a SAP macro using the option on SAP with “Script Recording & Playback”- we were using that VBS scripting and was working fine but today we notice that all SAP references were change example
Before Field for QA01 for the order
session.findById("wnd[0]/usr/sub/1/ctxt[4]").text
After - The same Field for QA01 for the order
session.findById("wnd[0]/usr/subLOT_HEADER:SAPLQPL1:1102/ctxtQALS-CHARG").text
- what could have caused this issue? from the suddenly all SAP if you record a script now the references come with different names than before?
Is something related to FIORI? Belize Theme? (Belize theme is unchecked on the Options of SAPGUI -
Was the SAP GUI API or was the SAP?
Why these change? An trasport or an options in an installatio, update or plugin - and if this is the case what is the option or the type of transport that affect this "
This is probably because of the migration/version upgrade wherein the field names changed. For ex, before upgrade a tcode was XYZ, lets say, however post migration few enhancements must have been included in it, thereby, updating some Auth objects, programs/screen fields which together constitute the technical names which you are seeing in the above code.
Guys,
I know is a old post, but very useful post and thought someone might be able to help me.
-----------------------------------------------------------------------------
Am creating a script to create 1000 Plans in Maintenance.
Tcode used : IP41
1, How do i account for drop down selection in maintenance plan category in the first screen. Also once i go inside the tcode there is a drop down for priority, but these fields do not appear as text in the script. How can i accommodate this? Also do i need to create a separate column in my input sheet for dropdown fields too?
2. Am getting an error object required "Active workbook"
Where am i making the mistake? Here is my code for your review.
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
REM ADDED BY EXCEL *************************************
Dim objExcel
Dim objSheet, intRow, i
Set objExcel = GetObject(,"Excel.Application")
Set objSheet = objExcel.ActiveWorkbook.ActiveSheet
For i = 7 to objSheet.UsedRange.Rows.Count
COL1 = Trim(CStr(objSheet.Cells(i, 1).Value)) 'Column1
COL2 = Trim(CStr(objSheet.Cells(i, 2).Value)) 'Column2
COL3 = Trim(CStr(objSheet.Cells(i, 3).Value)) 'Column3
COL4 = Trim(CStr(objSheet.Cells(i, 4).Value)) 'Column4
COL5 = Trim(CStr(objSheet.Cells(i, 5).Value)) 'Column5
COL6 = Trim(CStr(objSheet.Cells(i, 6).Value)) 'Column6
COL7 = Trim(CStr(objSheet.Cells(i, 7).Value)) 'Column7
REM ADDED BY EXCEL *************************************
session.findById("wnd[0]/tbar[0]/okcd").text = "/nIP41"
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/usr/cmbRMIPM-MPTYP").key = "PM"
session.findById("wnd[0]/usr/cmbRMIPM-MPTYP").setFocus
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/usr/subSUBSCREEN_HEAD:SAPLIWP3:6000/txtRMIPM-WPTXT").text = COL1
session.findById("wnd[0]/usr/subSUBSCREEN_MPLAN:SAPLIWP3:8001/tabsTABSTRIP_HEAD/tabpT\01/ssubSUBSCREEN_BODY1:SAPLIWP3:8011/subSUBSCREEN_CYCLE:SAPLIWP3:0205/txtRMIPM-ZYKL1").text = COL4
session.findById("wnd[0]/usr/subSUBSCREEN_MPLAN:SAPLIWP3:8001/tabsTABSTRIP_HEAD/tabpT\01/ssubSUBSCREEN_BODY1:SAPLIWP3:8011/subSUBSCREEN_CYCLE:SAPLIWP3:0205/ctxtRMIPM-ZEIEH").text = COL5
session.findById("wnd[0]/usr/subSUBSCREEN_MITEM:SAPLIWP3:8002/tabsTABSTRIP_ITEM/tabpT\11/ssubSUBSCREEN_BODY2:SAPLIWP3:8022/subSUBSCREEN_ITEM_1:SAPLIWO1:0100/ctxtRIWO1-TPLNR").text = COL2
session.findById("wnd[0]/usr/subSUBSCREEN_MITEM:SAPLIWP3:8002/tabsTABSTRIP_ITEM/tabpT\11/ssubSUBSCREEN_BODY2:SAPLIWP3:8022/subSUBSCREEN_MAINT_ITEM_TEXT:SAPLIWP3:6005/txtRMIPM-PSTXT").text = COL6
session.findById("wnd[0]/usr/subSUBSCREEN_MITEM:SAPLIWP3:8002/tabsTABSTRIP_ITEM/tabpT\11/ssubSUBSCREEN_BODY2:SAPLIWP3:8022/subSUBSCREEN_ITEM_1:SAPLIWO1:0100/ctxtRIWO1-TPLNR").setFocus
session.findById("wnd[0]/usr/subSUBSCREEN_MITEM:SAPLIWP3:8002/tabsTABSTRIP_ITEM/tabpT\11/ssubSUBSCREEN_BODY2:SAPLIWP3:8022/subSUBSCREEN_ITEM_1:SAPLIWO1:0100/ctxtRIWO1-TPLNR").caretPosition = 5
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/usr/subSUBSCREEN_MITEM:SAPLIWP3:8002/tabsTABSTRIP_ITEM/tabpT\11/ssubSUBSCREEN_BODY2:SAPLIWP3:8022/subSUBSCREEN_ITEM_2:SAPLIWP3:0500/ctxtRMIPM-AUART").text = COL3
session.findById("wnd[0]/usr/subSUBSCREEN_MITEM:SAPLIWP3:8002/tabsTABSTRIP_ITEM/tabpT\11/ssubSUBSCREEN_BODY2:SAPLIWP3:8022/subSUBSCREEN_ITEM_2:SAPLIWP3:0500/ctxtRMIPM-ILART").text = COL7
session.findById("wnd[0]/usr/subSUBSCREEN_MITEM:SAPLIWP3:8002/tabsTABSTRIP_ITEM/tabpT\11/ssubSUBSCREEN_BODY2:SAPLIWP3:8022/subSUBSCREEN_ITEM_2:SAPLIWP3:0500/ctxtRMIPM-ILART").setFocus
session.findById("wnd[0]/usr/subSUBSCREEN_MITEM:SAPLIWP3:8002/tabsTABSTRIP_ITEM/tabpT\11/ssubSUBSCREEN_BODY2:SAPLIWP3:8022/subSUBSCREEN_ITEM_2:SAPLIWP3:0500/ctxtRMIPM-ILART").caretPosition = 3
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/usr/subSUBSCREEN_MITEM:SAPLIWP3:8002/tabsTABSTRIP_ITEM/tabpT\11/ssubSUBSCREEN_BODY2:SAPLIWP3:8022/subSUBSCREEN_ITEM_2:SAPLIWP3:0500/cmbRMIPM-PRIOK").key = "2"
session.findById("wnd[0]/usr/subSUBSCREEN_MITEM:SAPLIWP3:8002/tabsTABSTRIP_ITEM/tabpT\11/ssubSUBSCREEN_BODY2:SAPLIWP3:8022/subSUBSCREEN_ITEM_2:SAPLIWP3:0500/cmbRMIPM-PRIOK").setFocus
session.findById("wnd[0]/tbar[0]/btn[11]").press
session.findById("wnd[1]/usr/radSTART_VALUE_NO").setFocus
session.findById("wnd[1]/usr/radSTART_VALUE_NO").select
session.findById("wnd[1]/tbar[0]/btn[0]").press
session.findById("wnd[0]/tbar[0]/btn[3]").press
REM FINALIZATION CONTROL CHECK ************************
aux=col1 & " " & col2 & " " & col3 & " " & col4 & " " & col5 & " " & col6 & " " & col7
CreateObject("WScript.Shell”).run(“cmd /c @echo %date% %time% ” & aux & ” >> C:\Users\Nmiller\Desktop\VBSCRIPT\Script2.txt")
next
msgbox "Process Completed"
REM FINALIZATION CONTROL CHECK ************************
Thanks alot
Nureya
Hi,
Is you are still facing the issue, please send me couple of snaps to analyze further over write2arunesh@gmail.com
Hi Mariano/Others,
I've ran the below script but its throwing an error 'invalid character-', and I read the above comments tried with the solutions, again I'm facing same issue. Could anyone please help me? Thanks in advance!
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
Dim objExcel
Dim objSheet, intRow, i
Set objExcel = GetObject(,”Excel.Application”)
Set objSheet = objExcel.ActiveWorkbook.ActiveSheet
For i = 2 to objSheet.UsedRange.Rows.Count
COL1 = Trim(CStr(objSheet.Cells(i, 1).Value)) ‘Column1
COL2 = Trim(CStr(objSheet.Cells(i, 2).Value)) ‘Column2
COL3 = Trim(CStr(objSheet.Cells(i, 3).Value)) ‘Column3
COL4 = Trim(CStr(objSheet.Cells(i, 4).Value)) ‘Column4
COL5 = Trim(CStr(objSheet.Cells(i, 5).Value)) ‘Column5
COL6 = Trim(CStr(objSheet.Cells(i, 6).Value)) ‘Column6
REM ADDED BY EXCEL *************************************
session.findById("wnd[0]").maximize
session.findById("wnd[0]/tbar[0]/okcd").text = "/npa30"
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/usr/subSUBSCR_PERNR:SAPMP50A:0110/ctxtRP50G-PERNR").text = COL1
session.findById("wnd[0]/usr/subSUBSCR_PERNR:SAPMP50A:0110/ctxtRP50G-PERNR").caretPosition = 8
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/usr/tabsMENU_TABSTRIP/tabpTAB01/ssubSUBSCR_MENU:SAPMP50A:0400/subSUBSCR_TIME:SAPMP50A:0330/ctxtRP50G-BEGDA").text = COL2
session.findById("wnd[0]/usr/tabsMENU_TABSTRIP/tabpTAB01/ssubSUBSCR_MENU:SAPMP50A:0400/subSUBSCR_TIME:SAPMP50A:0330/ctxtRP50G-ENDDA").text = COL3
session.findById("wnd[0]/usr/tabsMENU_TABSTRIP/tabpTAB01/ssubSUBSCR_MENU:SAPMP50A:0400/subSUBSCR_ITKEYS:SAPMP50A:0350/ctxtRP50G-CHOIC").text = COL4
session.findById("wnd[0]/usr/tabsMENU_TABSTRIP/tabpTAB01/ssubSUBSCR_MENU:SAPMP50A:0400/subSUBSCR_ITKEYS:SAPMP50A:0350/ctxtRP50G-SUBTY").text = COL5
session.findById("wnd[0]/usr/tabsMENU_TABSTRIP/tabpTAB01/ssubSUBSCR_MENU:SAPMP50A:0400/subSUBSCR_ITKEYS:SAPMP50A:0350/ctxtRP50G-SUBTY").setFocus
session.findById("wnd[0]/usr/tabsMENU_TABSTRIP/tabpTAB01/ssubSUBSCR_MENU:SAPMP50A:0400/subSUBSCR_ITKEYS:SAPMP50A:0350/ctxtRP50G-SUBTY").caretPosition = 4
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/tbar[1]/btn[5]").press
session.findById("wnd[0]/usr/txtP2010-STDAZ").text = COL6
session.findById("wnd[0]/usr/txtP2010-STDAZ").setFocus
session.findById("wnd[0]/usr/txtP2010-STDAZ").caretPosition = 9
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]").sendVKey 11
REM FINALIZATION CONTROL CHECK ************************
aux=col1 & ” ” & col2 & ” ” & col3 & ” ” & col4 & ” ” & col5 & ” ” & col6
CreateObject(“WScript.Shell”).run(“cmd /c @echo %date% %time% ” & aux & ” >> C:\SCRIPT\PlOrCreationLog.txt”)
next
msgbox “Process Completed”
REM FINALIZATION CONTROL CHECK ************************
Regards,
Thangaraj
Hello,
I’d like to know a fix if I have a different format of excel as source of data. Or do you also have tutorial for Fixed assets transactions?
Thank you so much!
HOW CAN I PASTE A COMPLETE COLUMN?
TRANSACTION
/sapapo/sdp94
CODE:
If m = Workbooks(“Script SAP OLP.xlsm”).Worksheets(“Menu”).Cells(j, 2) Then
‘SAP Script
session.findById(“wnd[0]/usr/subSUB_MAIN:/SAPAPO/SAPLMSDP_SDP:0027/cntlSDP_CUSTOM_CONTROL/” _
& “shellcont/shell/shellcont[0]/shell/shellcont[0]/shell”).doubleClickCell 6, 2
session.findById(“wnd[1]/tbar[0]/btn[0]”).press
session.findById(“wnd[0]/usr/subSUB_MAIN:/SAPAPO/SAPLMSDP_SDP:0027/cntlSDP_TLB_CUSTOM_CONTROL” _
& “/shellcont/shell”).pressButton “MSDP_ADVD_4PY84DRISMH_9526UPA726Y_6EOX9BGWXX4SNCKUI798LR9ND”
session.findById(“wnd[1]/usr/chkZOLP_INIT_T-BB_INIT”).Selected = True
session.findById(“wnd[1]/usr/txtZOLP_INIT_T-/BIC/ABANK_BLD”).Text = “0”
session.findById(“wnd[1]/usr/chkZOLP_INIT_T-BB_INIT”).SetFocus
session.findById(“wnd[1]/tbar[0]/btn[11]”).press
‘EXCEL data
u = Workbooks(myOwnFile).Worksheets(“OLP”).Cells(f, c).End(xlDown).Row
x = 7
y = 3
For f = 1 To u
If f = u Then
f = 1
Exit For
End If
session.findById(“wnd[0]/usr/subSUB_MAIN:/SAPAPO/SAPLMSDP_SDP:0027/cntlSDP_CUSTOM_CONTROL/” _
& “shellcont/shell/shellcont[0]/shell/shellcont[0]/shell”).setCellValue x, y, _
Workbooks(myOwnFile).Worksheets(“OLP”).Cells(f + 1, c).Value ‘HOW CAN I PASTE A COMPLETE COLUMN
y = y + 1
Next
Hi,
Is it possible for you to send couple of snaps over my email write2arunesh@gmail.com to analyze further?
@marianoc-
I'm not able to generate LogFile and message after SAP GUI script run using .vbs file. I'm able to do changes in material master using same script. However facing 2-issues as below-
issue1-Not able to generate LogFile after script run at given path whether successful or failed
issue2-Script isn't able to handle if there is "No changes" have been done in current material .Screen gets stucked for given material if doesn't find any new input to be changed
----------My sample 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
REM ADDED BY EXCEL *************************************
Dim objExcel
Dim objSheet, intRow, i
Set objExcel = GetObject(,"Excel.Application")
Set objSheet = objExcel.ActiveWorkbook.ActiveSheet
For i = 2 to objSheet.UsedRange.Rows.Count
COL1 = Trim(CStr(objSheet.Cells(i, 1).Value)) 'Column1
COL2 = Trim(CStr(objSheet.Cells(i, 2).Value)) 'Column2
COL3 = Trim(CStr(objSheet.Cells(i, 3).Value)) 'Column3
COL4 = Trim(CStr(objSheet.Cells(i, 4).Value)) 'Column4
COL5 = Trim(CStr(objSheet.Cells(i, 5).Value)) 'Column5
COL6 = Trim(CStr(objSheet.Cells(i, 6).Value)) 'Column6
REM ADDED BY EXCEL *************************************
session.findById("wnd[0]/tbar[0]/okcd").text = "/nMM02"
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/usr/ctxtRMMG1-MATNR").text = COL1
session.findById("wnd[0]/usr/ctxtRMMG1-MATNR").caretPosition = 8
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[1]/tbar[0]/btn[19]").press
session.findById("wnd[1]/usr/tblSAPLMGMMTC_VIEW").getAbsoluteRow(0).selected = true
session.findById("wnd[1]/tbar[0]/btn[0]").press
session.findById("wnd[0]/usr/tabsTABSPR1/tabpSP01/ssubTABFRA1:SAPLMGMM:2004/subSUB4:SAPLMGD1:2007/txtMARA-BRGEW").text = COL2
session.findById("wnd[0]/usr/tabsTABSPR1/tabpSP01/ssubTABFRA1:SAPLMGMM:2004/subSUB1:SAPLMGD1:1002/txtMAKT-MAKTX").text = COL3
session.findById("wnd[0]/usr/tabsTABSPR1/tabpSP01/ssubTABFRA1:SAPLMGMM:2004/subSUB4:SAPLMGD1:2007/txtMARA-BRGEW").setFocus
session.findById("wnd[0]/usr/tabsTABSPR1/tabpSP01/ssubTABFRA1:SAPLMGMM:2004/subSUB4:SAPLMGD1:2007/txtMARA-BRGEW").caretPosition = 1
session.findById("wnd[0]/usr/tabsTABSPR1/tabpSP19").select
session.findById("wnd[1]/usr/ctxtRMMG1-WERKS").text = COL4
session.findById("wnd[1]/usr/ctxtRMMG1-LGORT").text = COL5
session.findById("wnd[1]/usr/ctxtRMMG1-LGORT").setFocus
session.findById("wnd[1]/usr/ctxtRMMG1-LGORT").caretPosition = 4
session.findById("wnd[1]/tbar[0]/btn[0]").press
session.findById("wnd[0]/usr/tabsTABSPR1/tabpSP19/ssubTABFRA1:SAPLMGMM:2000/subSUB6:SAPLZMPRFIELDCUSTOMIZATION:9001/cmbMARD-ZZINVENTORIED").key = COL6
session.findById("wnd[0]/usr/tabsTABSPR1/tabpSP19/ssubTABFRA1:SAPLMGMM:2000/subSUB6:SAPLZMPRFIELDCUSTOMIZATION:9001/cmbMARD-ZZINVENTORIED").setFocus
session.findById("wnd[0]/usr/tabsTABSPR1/tabpSP02").select
session.findById("wnd[0]/usr/tabsTABSPR1/tabpSP24").select
session.findById("wnd[0]/tbar[0]/btn[11]").press
REM FINALIZATION CONTROL CHECK ************************
aux=col1 & " " & col2 & " " & col3 & " " & col4 & " " & col5 & " " & col6
CreateObject("WScript.Shell").run("cmd /c @echo %date% %time% " & aux & " >> C:\Users\Desktop\Script\MM02-New.txt")
next
msgbox "Process Completed"
REM FINALIZATION CONTROL CHECK ************************
Hi Aparajita,
Is the issue resolved per your post? If not, could you please send a step by step snap of the activity you are performing over my email "write2arunesh@gmail.com"? I have been working with GUI scripting since 2015, so hopefully I shall be able to solve your issue.