When You learn to record script in SAP, your report work become a lot easier and faster. But what do these recorded, SAP secret code lines after session.findbyid mean?
I already posted about How to connect to SAP via Excel VBA, where I present my approach to SAP connection with Excel VBA. So now let’s go to the meaning of some ID’s, which can help You to modify or repair your recorded script.
When I first saw recorded SAP code I felt like in Matrix. Tons of lines, where I only recognize what I was manually filling in SAP during recording.
But after some time I realized what some of that secret code lines mean. Thanks to that I could modify my code without re-recording. It allows me to shortage my code erasing unnecessary lines or putting my own variables into SAP code.
I would like to cut that whole, long journey experience and speed it up for You. For better understanding what hides behind SAP session.findbyid.
SAP code lines and their descriptions
1. SAP main window.
You may notice that the abbreviation wnd comes from word window. Number zero starts numbering SAP windows and not only them. You’ll find out more windows in your code like wnd or wnd.
2.Minimize and maximize the SAP window.
You can hide SAP window (.iconify) not to see any action on main stage wnd or maximize (.maximize) to fullscreen.
Above line stands for confirmation. In other words it is classic ENTER button. So every time You click it during recording You’ll get this line.
session.findById("wnd/tbar/okcd").Text = "transaction name"
This time let’s take a look at the structure. Firstly comes window and its index – wnd, then toolbar – tbar and transaction/ commands window on it – okcd. There is also .Text, which means that You are filling this textbox. Here You can pass transaction name or string variable.
Here You can see in structure as second item – usr. I’m not sure about that, but it rather stands for userform. Next to it is button nr 1 – btn. Every time You click button, that action will be recorded as .press.
session.findById("wnd/usr/ctxt").caretPosition = 4
If You have ever seen .caretPosition it means that your cursor is in position, in our case it is after 4th sign in that text container – ctxt. In most cases it is completely unnecessary line, so You can delete it to make your SAP code more transparent.
This is the second unnecessary SAP code line in my opinion. It is responsible for selecting window or text. Also feel free to delete it and it won’t affect on anything.
session.findById("wnd/usr/chk").Selected = True
If You have any checkbox in your transaction, it will appear in code as chk and its .Selected status – in our case it is True.
I think You know what I mean by saying “Red cross” on your main toolbar. After couple of recordings I realized that code line stands for cancel button. Use it to go back in SAP.
In the end I got for you code line for closing SAP. With closing line comes also confirmation pop up, which is next window wnd with yes button btn.
And this was it!
That was my 10 code lines, which often follow session.findbyid in SAP. Realizing what they mean and what they stands for allowed me to have better control over the code and to optimize it. I hope it will help as well.