SapGuiSetFocus Function

Action

Sets the focus to the specified control.

Include file

SapGui.bdh

Syntax

SapGuiSetFocus( in sControlId : string allownull, 
                in sTimer     : string optional ) :  boolean;
Parameter Description
sControlId The id of the control that should gain the focus.
sTimer Timer name used for measurements.

Return value

  • true if successful
  • false otherwise

Example

transaction TMain
  var
    sConnID : string;
  begin
    // Connecting to SAP
    sConnID := SapGuiOpenConnection(" /SAP_CODEPAGE=1100 /FULLMENU 10.5.2.198 0 /3");
    SapGuiSetActiveConnection(sConnID);
    SapGuiSetActiveSession("ses[0]");

    // SAP
    SapGuiSetActiveWindow("wnd[0]", "SAP", SAPGUI_MATCH_Exact);
    SapGuiWindowAction(SAPGUI_WND_MAXIMIZE);

    // Logon to SAP System
    // Before running a test you have to customize the password parameter!
    SapGuiIgnoreError(SAPENGINE_STATUSBAR_CHANGED, SEVERITY_SUCCESS);
    ThinkTime(3.8);
    SapGuiLogon("ddic", "*******", "000", "");

    // Copyright
    SapGuiSetActiveWindow("wnd[1]", "Copyright", SAPGUI_MATCH_Exact);
    SapGuiPressButton("tbar[0]/btn[0]");

    // SAP Easy Access
    ThinkTime(4.0);
    SapGuiSetActiveWindow("wnd[0]", "SAP Easy Access", SAPGUI_MATCH_Exact);

    // NodeName: Office
    // NodePath: 2\1
    SapGuiTreeExpandNode("usr/cntlIMAGE_CONTAINER/shellcont/shell/shellcont[0]/shell", "Office", 
    "0000000003", "Expand\\Office");

    // NodeName: Workplace
    // NodePath: 2\1\1
    SapGuiTreeSelectNode("usr/cntlIMAGE_CONTAINER/shellcont/shell/shellcont[0]/shell", "Workplace", 
    "0000000004", false,"SelNode\\Workplace");

    // NodeName: Favorites
    // NodePath: 1
    SapGuiSelectTopNode("usr/cntlIMAGE_CONTAINER/shellcont/shell/shellcont[0]/shell", "Favorites", 
    "Favo", "TopNode\\Favorites");

    // NodeName: Workplace
    // NodePath: 2\1\1
    SapGuiTreeDblClickNode("usr/cntlIMAGE_CONTAINER/shellcont/shell/shellcont[0]/shell", "Workplace", 
    "0000000004", "DblClNode\\Workplace");
    // Grid Control Info:
    // /app/con[0]/ses[0]/wnd[0]/usr/cntlSINWP_CONTAINER/shellcont/shell/shellcont[1]/shell/shellcont[0]/shell/0 columns
    // -------------------------------------

    // Business Workplace von DDIC
    ThinkTime(3.2);
    SapGuiSetActiveWindow("wnd[0]", "Business Workplace von DDIC", SAPGUI_MATCH_Exact);

    // Find folder
    ThinkTime(3.6);
    SapGuiPressButton("tbar[1]/btn[17]", " Find folder");

    // Folder Selection
    ThinkTime(50.2);
    SapGuiSetActiveWindow("wnd[1]", "Folder Selection", SAPGUI_MATCH_Exact);
    SapGuiSetText("usr/ctxtSOS06-S_FOLNAM", "d");
    SapGuiSetFocus("usr/txtSOS06-S_FOLDES");

    // caretPosition
    SapGuiSetProperty("usr/txtSOS06-S_FOLDES", "caretPosition", "0");
    SapGuiPressButton("tbar[0]/btn[12]");
  end TMain;