Recording the Sap Macro

Recording the Sap Macro

📎 This article includes 1 downloadable practice file ↓

⏱ 5 min readUpdated 13 October 2026

Recording the Sap Macro

When you are ready to perform the recording,  be sure you know the transaction you want to execute and the data that you can use.  You should also know the screens you plan to visit and the fields that you will be filling in.  You can always update the recording file, but the better your recording, the less errors you will encounter.

In this article
  1. Recording the Sap Macro
  2. SAP Macro in Excel
  3. Continue learning

The important thing to remember is that GUI script can NOT perform any logic.  it only works for repeating the same steps over and over again.  This means that if you receive an error on some records, but not others, you will need to execute 2 different scripts.  One script will do the non errors, and other script will do the errors.  You can cut down a lot of time if you can segregate the data early.

Advertisement

Recording the Sap Macro 1

 

Activate the recorder.  It is encouraged to always start the main screen in SAP.  This prevents weird things that happens if an error occurs during the playback.

Recording the Sap Macro 2

 

Press More if you want to control where the file is saved.

Recording the Sap Macro 3

 

When you are ready to start, press the record button (Red Dot Button). Then proceed to execute the transaction you wish to record.

Recording the Sap Macro 4

 

Be sure to use ‘/N’ in front of the transaction code for opening Transaction Code in same window and ‘/O’ in front of the transaction code for opening Transaction Code in new window.

Recording the Sap Macro 5
Enter in the document number and press Operations Button.

Recording the Sap Macro 6

 

When I added a new operation, I entered it on the bottom of the screen.  This allows you to avoid the risk of overriding exisitng data.

Press Enter.
Press Components Tab

Recording the Sap Macro 7

 

Again, add the data to the bottom of the screen.
Press Enter
Press Save
Sometimes there will be errors.  If errors occur, you need to remember that maybe not Every order you change will have the error.
Recording the Sap Macro 8
I encourage you to press the green arrow back on every recording at the end.  This just helps to avoid incorrect loading of data.
Recording the Sap Macro 9
Press stop.
Now, go find the file.  Be sure to RIGHT click on it.  If you double click on it, it will attempt to execute the exact same transaction again.
You should see something similar to this:

Recording the Sap Macro 10
The parts of this file you care about are the lines that start: session.xxx
Next up, add this information to the excel file.

SAP Macro in Excel

This will depend on your version of excel, but what you need to do is find the macro button:

Recording the Sap Macro 11
Be sure to enable macros.
Recording the Sap Macro 12
When the macro window opens, be sure to select the correct view on the left hand side of the screen.  Then move to the code section and find the area shown that says “Paste your recorded script below”.
If there is anything currently in this section, be sure to remove it, and replace it with the information from your recording (session.xxx).

Recording the Sap Macro 13

Now, I’m going to show you how to point this to your excel document.
session.findById(“wnd[0]/tbar[0]/okcd”).text = “/niw32”

session.findById(“wnd[0]”).sendVKey 0

Change:
session.findById(“wnd[0]/usr/ctxtCAUFVD-AUFNR”).text = “4000000”
To:
session.findById(“wnd[0]/usr/ctxtCAUFVD-AUFNR”).text = A

session.findById(“wnd[0]/tbar[1]/btn[17]”).press

Change:
session.findById(“wnd[0]/usr/subSUB_ALL:SAPLCOIH:3001/ssubSUB_LEVEL:SAPLCOIH:1107/tabsTS_1100/tabpVGUE/ssubSUB_AUFTRAG:SAPLCOVG:3010/tblSAPLCOVGTCTRL_3010/txtAFVGD-LTXA1[7,8]”).text = “my test op”
To:
session.findById(“wnd[0]/usr/subSUB_ALL:SAPLCOIH:3001/ssubSUB_LEVEL:SAPLCOIH:1107/tabsTS_1100/tabpVGUE/ssubSUB_AUFTRAG:SAPLCOVG:3010/tblSAPLCOVGTCTRL_3010/txtAFVGD-LTXA1[7,8]”).text = B

Since this can get long, I’ll jsut show you the first 2 changes.  You’ll notice that I found the first two lines where I entered in data.  I changed it to a single letter (no quotes).  This is the excel column where you enter in the data.  It’s that simple.  If anything is a constant, just leave it as it is.
When you’re done, press save and you’re ready to execute.

Executing the Script

Now, the first step before executing the script is gathering all the data.  Typically, this is done using SE16, SE16N, or certain reports (IW73, VA05, COOIS, etc).  As always, be careful with the data you enter.  It’s your user id that will be assigned to the change :).

Once you have the data you wish to execute, simply go the excel worksheet and execute the macro
*** NOTE:  Remember, when the script is running you can’t do anything with Excel.  You can continue working in SAP, but Excel will be locked for the duration of the script.

Recording the Sap Macro 14
**** NOTE ***
This is a VERY important one.  Be sure that the first SAP window open on your screen is the client you wish to change.  If you are doubt, be sure to logout of any client/system you do not want to change.  For example, if you are logged into production and QA.  You want to make the change to QA, I encourage you to log out of production.

Recording the Sap Macro 15
Press Run
Note:  if you have multiple excel windows open, be sure the correct macro name is highlighted.  If you aren’t sure, close the other excel documents.

Recording the Sap Macro 16

 

Gui Script will always give you a chance to check the results of the FIRST record.

Recording the Sap Macro 17

 

I encourage you to always check and make sure it saved properly before pressing ok.  If it did not, press cancel.  Otherwise the script will go all the way to the end.

Once you are done, it will return control back to excel.

Recording the Sap Macro 18

 

As long as you see OK in the row, the record processed.  if you don’t see ok, you’ll need to check that record and possibly reprocess it.

📎 Practice files for this article

  • 📄
    Example recorded script (.vbs)Practice file from the matching course lesson.
    ⬇ VBS · 649 B

Free to use for learning. Files with macros (.bas) are plain text — import them with Alt+F11 → File → Import File, and always test on a copy.

✨ Ask AI about this article

Stuck on a step? Ask a question and the AI answers using this article.

Free · AI can be wrong