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.


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.


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


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.



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.



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”


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[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.

Author: Tomasz Płociński

I'm very advanced in VBA, Excel, also easily linking VBA with other Office applications (e.g. PowerPoint) and external applications (e.g. SAP). I take part also in RPA processes (WebQuery, DataCache, IBM Access Client Solutions) where I can also use my SQL basic skillset. I'm trying now to widen my knowledge into TypeScript/JavaScript direction.

62 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. Thank you Tomasz, great quick overview, very helpful. Keep going, its very inspirative!

  5. 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.



    Run-time error ‘619’:

    The control could not be found by id.

    Thank you for your help!

      1. Hello, thanks for sharing, this was very helpful!
        I need to close the session in SAP but unfortunately the commands for clossing are just showing the pop up window “unsaved data will be lost”, I don’t know if I am missing something or how can I make it works,
        Thank you very much for your help! SAP guru 🙂

    1. Very late but below is solution of the error –


      btnSPOP-OPTION1 – is for Yes
      btnSPOP-OPTION1 – is for No

  6. session.findById(“wnd[0]/usr/ctxtS_BUKRS-LOW”).text = “277”

    Hi, I need to run this Code in excel VBA.
    and value 277 is based on the excel cell Value in A2,A3,a4 …etc

    How can I do this.. Please help!

    Thanks in advance!

    1. Just simply instead of “277” put there variable responsible for the cell value, for example:
      session.findById(“wnd[0]/usr/ctxtS_BUKRS-LOW”).text = ThisWorkbook.Sheets(1).Range(“A1”).Value

  7. Just wanted to say thank you so much for this post, it’s exactly what I’ve been looking for, and has been a game changer for me today. Finally getting my reports automated!

  8. Hai Tomasz

    Hope you are doing good!

    Thanks for great work! your script helped me in many ways
    I have another query can i know how to copy the text from SAP

    For eg. ctrl+y we select text in sap gui screen i need to copy that value and paste in sheet

    1. Hi Ganesh
      Thanks! Hope You good too!
      To copy the value/text from SAP try to record its window/placeholder/checkbox ID and use its value/text property.

  9. Hallo Tomasz,
    deinen Blog über SAP-Scripting finde ich sehr interessant.
    Ich möche einige Abläufe im SAP automatisieren.
    Dazu muss ich Daten von einer Transaktion in andere übertragen.
    Leider habe ich es bisher nicht geschafft, von einer Transaction zur anderen und wieder zurück zu wechseln.
    Wenn ich aus einer Transaktion im Code über “/n…” einer ander Transaktion starte, wird die ursprüngliche Transaktion geschlossen und ich muss wieder von vorne starten.
    Starte ich die nächste Transaktion über “/o…” wird das Script in der “neuen” Transaktion nicht weiter ausgeführt.
    Gibt es eine Möglichkeit so ein Transaktionshopping zu automatisieren?

  10. Hi Tomasz,
    first of all, thanks for sharing all these helpful information – most of the times, it is exactly what I was looking for 🙂 #thumpsup
    I just started my first “project” on connecting to SAP via Excel. Of course, I read your post about how to connect to SAP and just copied the code. The login works fine, however, with the transaction I always receive the error “method FINDBYID of object ISAPSESSIONTARGET failed”. If I enter the code within the login window (wnd[0]), the string get passed to the bar, no errors (even it makes no sense at all to put it there).
    What am I missing, any ideas?

  11. Hi Tomasz,

    Good topic! much appreciated.
    Wanted to add that ” – usr. I’m not sure about that, but it rather stands for userform. ”
    according to SAP help appears to stand for guiUSeRarea .
    It instructs the visual basic ‘findbyid’ function that the control is to be found with the guiuserarea screen element.

    lots (perhaps too much 😉 of info on

    Many thanks for your posts!

  12. Hi thomas

    I just want to catch information for the bottom line in SAP windows
    where appears : Browser a been opened, taxes has to be managed …. or where flag errors appears.

    How to save this text in vbs


    1. Hello
      This is simple Status bar, use its text property to get the info 🙂

  13. I have a series of records that I need to add a reference to Nuclear Electric Insurance Limited to the existing title. Unfortunately, the titles of the records vary, so I cannot use a standard session.findById(“wnd[0]/tbar[0]/okcd”).Text = “” line.

    Is there a way to keep the existing field data and add “(NEIL)” to the end of it?

  14. For each of the records shown below (this is just 4 of the 239 records that I need to update), I am looking to add “(NEIL)” to the maintenance item description.
    Plan Item Description
    10174 114874 Clean and Flush Vacuum Pump Interior
    12560 117270 SVI-E21T2001 LPCS Pmp & Vlv OPER
    12694 117394 Inspect Main Turbine Lube Oil Tank Gaske
    13797 118507 00001 REMOVE & EXAMINE ODBP DISCH CHK VL

    Going to the 1st one on the list, the current value for the Maintenance Item description is “Clean and Flush Vacuum Pump Interior”.

    I want to add “(NEIL)” to either the beginning or the end of the existing text.

    I could do that with session.findById(“wnd[0]/usr/subSUBSCREEN_MITEM:SAPLIWP3:8002/tabsTABSTRIP_ITEM/tabpT\11/ssubSUBSCREEN_BODY2:SAPLIWP3:8022/subSUBSCREEN_MAINT_ITEM_TEXT:SAPLIWP3:6005/txtRMIPM-PSTXT”).text = “(NEIL)Clean and Flush Vacuum Pump Interior”, but since the next record has a totally different description, I would need the next one to be “(NEIL)SVI-E21T2001 LPCS Pmp & Vlv OPER”.

    So what it comes down to is, the session.findById(“”).text= statement overwrites the existing data in that data field. But I do not want to overwrite the existing data, I want to add to it.

    What I have done in the past is to use a script to cycle through the maintenance plans, and I would use wscript.sleep(5000) to allow me time to select the location to insert the text, and then use CTRL+V to paste in what I am adding, before the script kicks back in to cycle on to the next record.

    While this works to save some time, I still have to be ready and waiting to select the insertion point and to do the CTRL+V in that 5 second window that the wscript.sleep(5000) gives me.

    If there is a way to append the existing data rather than overwrite it, I could create the script to do the entire batch of maintenance plans in one go.

    1. Hello Michael
      Have You tried something like this?
      session.findById(“”).text = session.findById(“”).text & "NEIL"

      1. I just tried that and received a ‘control could not be found’ error message (error code 800A026B).

        1. Follow-up. There might be some other issue going on here as I just recorded a new script, and when I went to run it, I got the same type of error. The script had not been edited in any way so there should have been no way to get the ‘control could not be found’ message.

          1. SAP must have been hung up on something. I closed all the way out of SAP, went back in and using the & “NEIL’ worked. Thanks for the help.

  15. One last comment and I’ll be done.

    I was able to tinker with it a little bit and found that I could write the script use a new variable called Current to temporarily store the current contents of the field, then use the & concatenation to set the field value to (NEIL) followed by the original field contents as shown below:

    Current = session.findById(“”).text
    session.findById(“”).text = “(NEIL)” & Current

    Thanks again for your help. I am sure that this will save me a bunch of time for this, and future projects.

    1. I’m really happy that I could help You at least a little bit 🙂

  16. Hi I am using: session.findById(“wnd[0]”).iconify and it works very well but some windows do not hide them as I could use when I have a confirmation window session.findById(“wnd[0]”).sendVKey 0

    this is my code:

    session.FindById(“wnd[0]/tbar[0]/okcd”).Text = “/NCOOIS”
    session.FindById(“wnd[0]/usr/tabsTABSTRIP_SELBLOCK/tabpSEL_00/ssub%_SUBSCREEN_SELBLOCK:PPIO_ENTRY:1200/ctxtS_WERKS-LOW”).Text = “CT01”
    session.FindById(“wnd[0]/usr/tabsTABSTRIP_SELBLOCK/tabpSEL_00/ssub%_SUBSCREEN_SELBLOCK:PPIO_ENTRY:1200/ctxtP_SYST1”).CaretPosition = 0
    session.FindById(“wnd[0]”).SendVKey 4 –OPEN WINDOW–

    thanks for your help

    1. Hi Charles,
      but what is the question? 🙂
      Iconify only hides, as far as I know, the main window – wnd[0]

      1. Hello, the idea is to hide any window, with this option Yes it hides the main one, but there are other confirmation or menu that leaves them visible, thanks

        1. Haven’t yet found solution for that. I think it is not doable unfortunately.

  17. Hello,

    I am trying to create a script but I run into the error “the control could not be found by id”.

    session.findById(“wnd[0]/usr/ctxtRIMR0-DFDAT”).Text = “14032023”
    session.findById(“wnd[0]/usr/sub:SAPLIMR0:4210/ctxtIMRG-IDATE[1,56]”).Text = “14032023”

    I basically want to insert a date into a field, but when the code reaches that part, i get that error.

    I read somewhere that I could refer to an element by its name. Could you explain me how? The code above is what I obtained by record the script on SAP.

  18. Hi Tomasz,
    I use Excel VBA to logon to SAP and run transactions.
    The problem:
    If the user has unread messages in the SAP Mail inbox,
    this window popup right after the logon and stops the macro.
    The question:
    How to add to the macro a command which push the green V in SAP and allow the macro to move forward?

    1. Hello
      I’m not really sure what are You talking about – what is SAP Mail inbox? What kind of popup window?
      Are You able to record this popup window? I need ‘bigger picture’ to help You 🙂

      Also before You answer please also check my other articles in SAP category like:

      1. Hi,
        I want to send you the popup window image.
        How to attach a picture here?

  19. Hello sir,
    I’m getting an OLE error while I run my VBA macro, this is to run a report in SAP. I’m getting this error “Microsoft excel is waiting for another application to complete an OLE action”. The report contains big dated information, I tried many ways to fix this OLE error but no luck. Your help could be very much appreciable. I need this to be fixed, I totally struck up, can’t move forward with my other projects

  20. Thank you so much.

    I’m learning SAP scripting and your post was really helpful.

Leave a Reply

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