SAP session.findbyid – 10 code lines you can identify

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?

SAP session.findbyid - what is this?

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.

session.findById("wnd[0]")

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[1] or wnd[2].

2.Minimize and maximize the SAP window.

session.findById("wnd[0]").iconify
session.findById("wnd[0]").maximize

You can hide SAP window (.iconify) not to see any action on main stage wnd[0] or maximize (.maximize) to fullscreen.

3.Confirmation

session.findById("wnd[0]").sendVKey 0

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.

4.Transaction name

session.findById("wnd[0]/tbar[0]/okcd").Text = "transaction name"

This time let’s take a look at the structure. Firstly comes window and its index – wnd[0], then toolbar – tbar[0] 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.

5.Buttons

session.findById("wnd[0]/usr/btn[1]").press

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[1]. Every time You click button, that action will be recorded as .press.

6.Cursor position

session.findById("wnd[0]/usr/ctxt[73]").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.

7.Focused

session.findById("wnd[0]/usr/ctxt[73]").SetFocus

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.

8.Check box

session.findById("wnd[0]/usr/chk[2]").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.

9.”Red cross”

session.findById("wnd[0]/tbar[0]/btn[12]").press

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.

10.Closing

session.findById("wnd[0]").Close
session.findById("wnd[1]/usr/btn[0]").press

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[1] with yes button btn[0].

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.

Tomasz Płociński

Author: Tomasz Płociński

Excel VBA enthusiast who is also open for other languages. Mainly working in VBA, some SQL, hungry for more.

15 thoughts on “SAP session.findbyid – 10 code lines you can identify”

  1. Thanks for sharing!
    BTW, you can find any ID for current SAP window using SAP official utility GUI_ScreenReader

  2. How can I get ID of used buttons, text boxes etc. used in a particular transaction?
    I can’t record a macro in SAP (I’m not authorized to use this transaction). Is it somehow to detect these IDs?

    1. Try to record it in test SAP, where You should have access to all transactions.

  3. Thanks Tomasz, it is really helpful !
    I am able to use macro to open SAP right now, do you know the macro script to select the 2nd button of my “selection screen” in the translation table? Thank you.

      1. Thanks Tomasz, It is really very helpful to my project! Now I get my SAP report by one click on Macro

  4. Hello, thank you for writing this blog post. I am trying to use the code to close and I get an error on the second confirmation window.

    line:

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

    Run-time error ‘619’:

    The control could not be found by id.

    Thank you for your help!

Leave a Reply

Your email address will not be published. Required fields are marked *