Purpose The .NET class library  guinet.dll provides a comfortable interface for calling SAP GUI scripting functions from .NET.

This can be a call of .NET function from GuiXT by using the command CallVBAsync (component GuiXT Controls) or an external .NET program that runs independently from GuiXT. Also the mobile applications of Synactive GmbH (S10 technology, CIS mobile) uses guinet.dll.

The events triggered by guinet.dll are logged in the GuiXT InputScript trace.

Prerequisites:

  • SAP GUI Scripting is activated on the SAP server and also on the client PC
     
  • The interface-classLibrary Interop.SAPFEWSELib.dll exists in the .NET directory. This file is created automatically by Visual Studio after adding a reference to the COM-Object "SAP GUI Scripting API" to the project.

    Please make sure that you include this reference after having set the .NET target framework to version 4.0. On compiling to target version 3.5 or below and copying the file  Interop.SAPFEWSELib.dll to the .NET directory some incompatibility problems will occur.
Calling the scripting functions In order to call the scripting functions please use the object guinet.GuiSession. The script will automatically work with the SAP GUI sessions from where CallVBAsync was called.

When using guinet.dll  in your own .NET program, independently from GuiXT CallVBAsync, it is necessary to start an SAP GUI session with GuiSession.Logon().

Example 1:

// start transaction FB01
var guixt = new guinet.guixt();

guixt.GuiSession().Enter("/NFB01");

// set company code
guixt.GuiSession().SetField("BKPF-BUKRS", "0001");


Example 2:

A more detailed example application can be found here:

GuiNET Demo

Calling "native" SAP GUI Scripting If you may need to call "native" SAP GUI scripting functions besides those provided by guinet.dll from your .NET function, then you can reach them via guixt.GuiSession.GuiApplication and  guixt.GuiSession.GuiActiveWindow.

Example 1:

MessageBox.Show("SAP GUI Version: "
	+ guixt.GuiSession().GuiApplication.MajorVersion);

Example 2:

guixt.GuiSession().GuiActiveWindow.FindById(
	"usr/ctxtBKPF-BUKRS").Text = "0001";


The notation of the native SAP GUI scripting reflects the internal subscreen structure of a SAP dynpro and is therefore only of much use in practise when recording scripts. E.g. the SAP GUI scripting standard notation in transaction VA01 is simplified from

guixt.GuiSession().GuiActiveWindow.findById;
  ("usr/subSUBSCREEN_HEADER:SAPMV45A:4021/subPART-SUB:
  SAPMV45A:4701/ctxtKUWEV-KUNNR").text = mykunnr;


with the  guinet-interface to

guixt.GuiSession().SetField("KUWEV-KUNNR", mykunnr);


and which can also be written down without script-recording, if one knows the technical fieldname "KUWEV-KUNNR" (e.g. by using F1 when the cursor is inside a SAP field).

The sap standard help for the SAP GUI scripting containing the description of all "native" functions is available in the SAP GUI via menu "Help to SAP GUI scripting".
 

Click()
public void Click(string name)

Mouseclick (single) on the given element (e.g. input/output field). Please provide the technical name of the element as "name".

Example:

// click on
Ship-to party;

guixt.guisession().Click( " KUWEV-KUNNR " )
ClickGridCell()
public void ClickGridCell(
    int row, string colname,
    int index = 0)

Mouseclick onto a cell inside a Grid Control.

ClickTableCell()
public void ClickTableCell(
    int row, string colname)

public void ClickTableCell(
    string tabname, int row,
    string colname)

Mouseclick into a cell inside a Table Control. The first variant can be used if there is only one table on the screen.

DoubleClick()
public void DoubleClick(string name)

Doubleblick onto the given element (e.g. input/output field). Please provide the technical name of the element as "name".

Example:

// doubleclick on
Ship-to party;

guixt.guisession().DoubleClick( " KUWEV-KUNNR " )
DoubleClickGridCell()
public void DoubleClickGridCell(
    int row, string colname,
    int index = 0)

Doubleclick onto a cell in a Grid Control.

DoubleClickTableCell()
public void DoubleClickTableCell(
    int row, string colname)

public void DoubleClickTableCell(
    string tabname, int row,
    string colname)

Doubleclick into a cell in a Table Control. The first variant can be used if there is only one table on the screen.

DoubleClickTreeNode()
public void DoubleClickTreeNode(
    string nodekey, int index = 0)

Doubleclick into a tree-node (key).

DoubleClickTreeItem()
public void DoubleClickTreeItem(
    string nodekey, string item,
    int index = 0)

Doubleclick onto an element of the tree. 

Enter()
public bool Enter(
    string cmd = "",
    bool IgnoreWarning = true,
    bool ReturnError = false,
    bool IgnoreInfoPopup = false,
    ref string msg)

Enter of a function-code, e.g.

guixt.guisession().Enter("=V43D_GET");

or

guixt.guisession().Enter("/NVA03");

The additions options can be used to define, of messages or popups should automatically be confirmed.

FindField()
public GuiComponent FindField(string name)

Searches an element via technical name and returns it as GuiComponent-object of the SAP GUI scripting. If nothing was found: Returns Nothing.

GetField()
public string GetField(
    string name, bool text = false)

The content of any input/output field, a checkbox, a radiobutton or a combobox. Please provide the technical name as "name". Example:

vbapnetwr = guixt.guisession.GetField("VBAP-NETWR")

  • Returning "" or "X" for checkboxes and radiobuttons
  • For comboboxes the value of the key is returned unless you provide the optional parameter "text" True,then the text instead of the value is returned. 
GetFieldIcon()
public string GetFieldIcon(string name)

Searches an element via technical name and returns the name of the icon, if the text starts with an icon, "" else.

GetGridCell()
public string GetGridCell(
    int row, string colname,
    int index = 0, ref bool found)

Reads the contenet of a cell in a Grid Control.

GetTableCell()
public string GetTableCell(
    int row, string colname)

public string GetTableCell(
    string tabname, int row,
    string colname)

Reads the content of a cell in a Table Control. The first variant can be used if there is only one table on the screen.

GuiGridView()
public GuiGridView GuiGridView { get; }

Returns the current Grid Control as GuiGridView object of the SAP GUI scripting or nothing, if there is no active grid. If there is more than one grid, the first one is returned.

GuiGridViews()
public List GuiGridViews { get; }

Return a list of all current grid controls.
 

GuiTableControl()
public GuiTableControl GuiTableControl { get; }

Returns the current Table Control as GuiTabelControl object of the SAP GUI scripting, or nothing, of there is no active TableControl.

Optional: The technical name of the table can be provided e.g.

GuiTableControl tc;
tc = guixt.guisession().GuiTableControl(
    "SAPMV45A_TCTRL_U_ERF_AUFTRAG");
GuiTree()
public GuiTree GuiTree { get; }

Returns the current Tree as GuiTree object of the SAP GUI Scripting or nothing, of there is no active Tree. If there is more than one tree the first one is returned.

GuiTrees()
public List GuiTrees { get; }

Returns a list of all currentr Trees.
 

IsTabActive()
public bool IsTabActive(string tabid)

Checks if a certain tab is active. Example:

if (guixt.guisession().IsTabActive("T/03"))
{
}
Logoff()
public bool Logoff()

The SAP GUI session will be closed.

Logon()
public bool Logon(
    ref string ParErrorMessage,
    bool HideWindow = false)

Only required on working without reference to GuiXT because with GuiXT the SAP GUI Scripting always refers to the current SAP GUI window.

Logs on to the SAP system using the parameters set on creating thte sapguisession-object (connectionstring, username etc.)

Optional: The SAP GUI window can be switched to invisible mode by using the parameter HideWindow. Then only the dialog-window of your .NET program is visible to the user and all SAP GUI actions will be processed in the background.

MessageId()
public string MessageId { get; }

The message class, e.g. "02".

MessageNumber()
public string MessageNumber { get; }

The message number, e.g. "100".

MessageParameter1()
public string MessageParameter1 { get; }

Parameter 1 in the message.

MessageParameter2()
public string MessageParameter2 { get; }

Parameter 2 in the message.

MessageParameter3()
public string MessageParameter3 { get; }

Parameter 3 in the message.

MessageParameter4()
public string MessageParameter4 { get; }

Parameter 4 in the message.

MessageText()
public string MessageText { get; }

The text of the message.

MessageType()
public string MessageType { get; }

If a message is displayed on the screen, the message type "E" for error, "I" for information and "W" for warning. Else "".

New()
public sapguisession(
    string ConnectionString,
    string LogonClient, string LogonUser,
    string LogonPassword,
    string LogonLanguage)

Only required on working without reference to GuiXT because with GuiXT the SAP GUI Scripting always refers to the current SAP GUI window and you can get the sapguisession-object by calling guixt.sapguisession().

Creates a new object of class guinet.sapguisession using the given parameters for the following logon().
 

NewSession()
public sapguisession NewSession(string tcode)

Starts a new SAP GUI mode with given transaction.

ReadGrid()
public bool ReadGrid(
    DataTable dt, int index = 0)

Read in the content of the current Grid Control into a .NET object of class System.Data.DataTable.

Those columns that have corresponding names in the DataTable object will be read.

If there is more than one Grid Control on the screen, you can provide the number as index.

ReadComboBox()
public bool ReadComboBox(
    DataTable dt, string name)

Read in the content of a combobox into a .NET object of class System.Data.DataTable.

The keys will be read into the first column, the texts into the second column.

ReadTable()
public bool ReadTable(
    DataTable dt, string tabname = "")

Read the content of a Table Control into a .NET object of class System.Data.DataTable.

Those columns that have corresponding names in the DataTable object will be read.

As "tabname" you can provide the technical name of the table.

ReadTree()
public bool ReadTree(
    DataTable dt, string nodekey = "",
    int index = 0, int depth = 100000)

Read the content of a tree as Vb.NET object of class System.Data.DataTable.

The following columns will be filled if they exist in the DataTable object:

  • nodekey
  • nodepath
  • nodetext
  • nodelevel
  • nodelabel

Optional: You can provide a node "nodekey" that functions as root for reading this sub-tree, the index 0,1,2 if there is more than one tree and the depth until the structure of the tree should be resolved.

ScreenId()
public string ScreenId { get; }

Returns the current program name and dynpro number e.g. " SAPMV45A.0100"
 

ScreenTitle()
public string ScreenTitle { get; }

Returns the current title, e.g. "Create Sales Order: Initial Screen"

SetField()
public void SetField(string name, string value)

Sets the content of an inputfield, a checkbox, a radiobutton or a combobox. Please provide the technical name as "name". Example:

guixt.guisession.SetField("RF02D-KUNNR", customernumber)

  • On using checkboxes or radiobuttons only "" or "X" can be set
  • On using a combobox, you set the value of the key, not the text
     
SetLicense()
public bool SetLicense(string license)

If you would like to use guinet.dll within your own .NET program without reference to GuiXT, then you have to provide a valid licensekey before using the logon-command. The "GuiXT controls" component includes this license; you can obtain the licensekey from Synactive.

SetGridCell()
public void SetGridCell(
    int row, string colname,
    string value, int index = 0)

Sets the content of a cell in a Grid Control.

SetTableCell()
public void SetTableCell(
    int row, string colname,
    string value)

public void SetTableCell(
    string tabname, int row,
    string colname, string value)

Sets the content of a cell in a Table Control. You can use the first variant if there is only one table on the screen.

SelectTableRow()
public void SelectTableRow(int row)

public void SelectTableRow(
    string tabname, int row)

Selects a  table-cell. You can use the first variant if there is only one table on the screen.

The table-cell will be scrolled into the visible sector of the table if neccessary.

TableCellExists()
public bool TableCellExists(
    int row, string colname,
    ref GuiComponent g)

public bool TableCellExists(
    string tabname, int row,
    string colname, ref GuiComponent g)

Checks if a certain table-cell exists. Optional: The table-cell will be provided as object of class GuiComponent.

The table-cell will be scrolled into the visible sector of the table if neccessary.

Component GuiXT + Controls