cancel
Showing results for 
Search instead for 
Did you mean: 

Find and select desired query through Script Registration and Playback

Former Member
0 Kudos

Hello everyone! I recently started working with SAP at my stage in the HR industry and the first challenge was to create a macro for Excel VBA that logs into SAP, uses the PAAH transaction and opens / executes a given query and saves the generated data in a worksheet in excel. I was able to create the script for VBA through the Script Registration and Playback tool in SAP and use the macro without problems. But I came across a problem: In script playback it takes the value of the line I selected at the time of recording. If a new query is added in this list of queries, the index of my query will change. My question is how do I always find the desired query and execute it even if the list changes. Below is the code I was using, obtained through the Registration and Playback Script:

Session.findById("wnd[0]").maximize

Session.findById("wnd[0]/tbar[0]/okcd").Text = "/npaah"

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

Session.findById("wnd[0]/tbar[1]/btn[6]").press

Session.findById("wnd[1]/usr/cmbDYNP4300-DD_WORKSPACE").SetFocus

Session.findById("wnd[1]/usr/cmbDYNP4300-DD_WORKSPACE").Key = "1"

Session.findById("wnd[1]/usr/cmbDYNP4300-DD_USERGROUP").SetFocus

Session.findById("wnd[1]/usr/cmbDYNP4300-DD_USERGROUP").Key = "102"

Session.findById("wnd[1]/usr/tblSAPLAQ_INT_FUNCTIONSTCH_OPEN_QUERIES").verticalScrollbar.Position = 2835

Session.findById("wnd[1]/usr/tblSAPLAQ_INT_FUNCTIONSTCH_OPEN_QUERIES").getAbsoluteRow(2837).Selected = True

Session.findById("wnd[1]/usr/tblSAPLAQ_INT_FUNCTIONSTCH_OPEN_QUERIES/txtDYNP4300_TC_QUERIES-NAME[0,2]").SetFocus

Session.findById("wnd[1]/usr/tblSAPLAQ_INT_FUNCTIONSTCH_OPEN_QUERIES/txtDYNP4300_TC_QUERIES-NAME[0,2]").caretPosition = 0

Session.findById("wnd[1]/tbar[0]/btn[0]").press

Session.findById("wnd[0]/shellcont[0]/shell").pressToolbarButton "GET_DATA"

Session.findById("wnd[0]/shellcont[0]/shell").pressToolbarContextButton "&MB_EXPORT"

Session.findById("wnd[0]/shellcont[0]/shell").selectContextMenuItem "&XXL"

Session.findById("wnd[1]/usr/ctxtDY_PATH").Text = "P:\Desktop\Teste"

Session.findById("wnd[1]/usr/ctxtDY_FILENAME").Text = "FUNCIONÁRIOS_SITUAÇÃO.XLSX"

Session.findById("wnd[1]/usr/ctxtDY_FILENAME").caretPosition = 13

Session.findById("wnd[1]/tbar[0]/btn[11]").press

Accepted Solutions (1)

Accepted Solutions (1)

stefan_schnell
Active Contributor
0 Kudos

Hello Jeancarlo,

welcome in the SAP Community.

To get the correct entry in the table you should code a loop in VBScript which detects the correct line.

You can find very good examples to do that here:

Please, use the search function, with the word GuiTableControl.

Best regards
Stefan

Former Member

Thank you very much Stefan! I'll read on.

Answers (1)

Answers (1)

Former Member
0 Kudos

Anyone help?

former_member186338
Active Contributor

Incorrect tags selected - result: no answer...

Former Member
0 Kudos

Hi Vadim! Thanks for informing! I'm new to the forum, could you tell me what the correct tags are for the subject? Thank you very much.

stefan_schnell
Active Contributor

Hello Jeancarlo and Vadim,

in my opinion is the tag correct. As far as I can see it is a SAP GUI Scripting question, how to search an entry in a GuiTableControl.

Best regards
Stefan