Sei sulla pagina 1di 6

Record and Playback 

(Quick and Easy way upload data in SAP)

This method can be used as an alternative to BDC for small data updates in SAP. Standard SAP method
like BDC, BAPI etc.. are always recommended for data upload over this method and should be used.(But
always good to have some extra knowledge). This method do not required any TR creation as it do not
generate any SAP code.

Step 1:

Login into SAP and click on Script Recording and Playback under Customization Local Layout from menu
bar.

It will open popup window,

If the option of Script Recording and Playback is deactivated, then you need to system parameter to
enable it.

To do so, go to Tcode RZ11 and enter parameter name as ​sapgui/user_scripting


Maintain the current value as TRUE.

Save and re-login. Script Recording and Playback should be activated now.

Step 2:​ Recording

In this step we will be recording the transaction, something similar to what we do in Tcode SHDB.

For recording the Tcode, click on the record button on the popup.

Once you will click on it you will be able to see Script Icon in SAP windows,

Demo Scenario: We want to change the description of multiple materials using MM02(basic view). Value
of new description is maintained in EXCEL.
Recording Steps:

a) Enter Tcode MM02


b) Enter material number
c) Select basic view
d) Change the description text of material
e) Save
f) Click on Stop recording button.

Once this step is done, script will be saved on your given location.

Step 3:

Once script is created, you can test it by clicking on Play button on Popup. You need to locate the
recorded script. Change description of material using MM02 for which recording is done and execute the
script. As a result material description will be changed to the description you have given while recording.

Step 4: Understanding the script

To see the content of the generated script, right click on script and click on edit, or open the Script in
Notepad.
In this script I have highlighted the values that we have entered for doing this transaction.
MM02(Tcode), 1001007(Material) and Test Descrp(Description).

Material and description we need to pick from excel and pass it to transaction MM02. Below is the code
you need to add in script to achieve this.

Code need to be inserted below “session.findById("wnd[0]").maximize”’ statement.

a) Code to open excel.


Important thing to keep in mind while doing this activity is, we need to keep excel sheet with the data
open, and only that excel should be open. No other excel sheet should be open.

This code will open the excel sheet to pick data.

b) Code to giving starting raw in excel.


We need to write the raw number from where the record should be starting. In my excel sheet, first raw
is for header, so I need to start to read the data from raw 2. Below is the code,

c) Pick values from excel column


My excel sheet contains two column, first for material and second for description. Below code is to pick
value from two column. You need to adjust your code accordingly.

d) Replacing value in recorded script


The script that is recorded contains value of material and description (or I can say hardcoded values).
This we need to replace with the values that we are picking from excel. Below code shows the
changes highlighted.

e) Code to show completed process


Finally you need to use below code that assigns col1 and col2 and gives message once the process is
complete.

Complete Script Code:


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

session.findById("wnd[0]/tbar[0]/okcd").text = "mm02"
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/usr/ctxtRMMG1-MATNR").text = COL1
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[1]/usr/tblSAPLMGMMTC_VIEW").getAbsoluteRow(0).selected = true
session.findById("wnd[1]").sendVKey 0
session.findById("wnd[0]/usr/subSUB2:SAPLMGD1:8001/tblSAPLMGD1TC_KTXT/txtSKTEXT-MAKTX[1,0]").text = COL2
session.findById("wnd[0]/usr/subSUB2:SAPLMGD1:8001/tblSAPLMGD1TC_KTXT/txtSKTEXT-MAKTX[1,0]").setFocus
session.findById("wnd[0]/usr/subSUB2:SAPLMGD1:8001/tblSAPLMGD1TC_KTXT/txtSKTEXT-MAKTX[1,0]").caretPosition = 12
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[1]/usr/btnSPOP-OPTION1").press
session.findById("wnd[0]/tbar[0]/btn[3]").press

aux=col1 & " " & col2


CreateObject("WScript.Shell").run("cmd /c @echo %date% %time% " & aux & " >> C:\SCRIPT\PlOrCreationLog.txt")
next
msgbox "Process Completed"

Step 4:
Final step is to test the script.
● Keep the excel sheet with data open. It should be the only excel sheet open on your system.
● Login into you SAP system and open the popup for Record and Playback.
● Click on play Icon and locate your script.
● You can get some warning message, click ok on it.
● If everything is fine, you will be able to see recoding being played for all the materials you have
provided in excel sheet.
● At the end you will get message, “Process Completed”.

Potrebbero piacerti anche