Select a layout in a list with SAP GUI Scripting

Sélection Layout Grid SAP GUI Scripting

After clicking “Select layout”, simply right click in the left column of the list, choose Search and type the name of the layout. That is all you need to select a layout in an SAP list.

There are two ways to automate this selection:

  • 1) record your macro and include the steps described in part I,
  • or 2) if the macro is already recorded, add the piece of code shown in part II.

I – Steps to add while recording a macro to select a layout in a list

  1. After clicking “choose layout”, right click in the left column of the list, as shown below:

Sélectionner un layout dans une liste

 

Select a layout in a list

  1. You will get the following window:

 

Layout search window

  1. Enter in the “Search Term” field the name of the layout you want to select, then confirm:

 

1 layout was found

  1. The layout is now selected. Close the window by clicking the red cross to go back to the previous list:

  1. The cursor has appeared on the layout you selected, confirm and you are done
  2. Once you have exported your table, you can integrate it directly into an Excel file by doing the following:

Template to easily insert your SAP table into Excel
  1. Once your table has been inserted into Excel, send it by email to your colleagues, we explain 4 very simple and effective methods to do it.

II – Code to add to the macro if you have already recorded your macro and do not want to record it a second time

  1. Right click your .vbs script file and open it in Notepad
  2. Insert the following block of code into your script:
objSess.FindById("wnd[0]/tbar[1]/btn[33]").Press 'correspond au clic sur le bouton "select layout"
objSess.FindById("wnd[1]/usr/ssubD0500_SUBSCREEN:SAPLSLVC_DIALOG:0501/cntlG51_CONTAINER/shellcont/shell").CurrentCellRow = -1
objSess.FindById("wnd[1]/usr/ssubD0500_SUBSCREEN:SAPLSLVC_DIALOG:0501/cntlG51_CONTAINER/shellcont/shell").SelectColumn "VARIANT"
objSess.FindById("wnd[1]/usr/ssubD0500_SUBSCREEN:SAPLSLVC_DIALOG:0501/cntlG51_CONTAINER/shellcont/shell").ContextMenu
objSess.FindById("wnd[1]/usr/ssubD0500_SUBSCREEN:SAPLSLVC_DIALOG:0501/cntlG51_CONTAINER/shellcont/shell").SelectContextMenuItem "&FIND"
objSess.FindById("wnd[2]/usr/txtGS_SEARCH-VALUE").Text = "/FR_CUT_REPO" 'indiquer ici entre guillements le nom du layout
objSess.FindById("wnd[2]/usr/txtGS_SEARCH-VALUE").CaretPosition = 12
objSess.FindById("wnd[2]/tbar[0]/btn[0]").Press

Related articles