Beruflich Dokumente
Kultur Dokumente
created by Mariano Cabalen on Aug 4, 2014 6:34 PM, last modified by Mariano Cabalen on Dec 4,
2014 5:15 PM
Version 4
inShare2
Object 1
Object 2
Object 3
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.
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.
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:
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 *************************************
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"
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
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!!
Note
that you must enter the values in upper case;
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 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.