This example acquires the user names and the address data of all users in the SAP system.
Basis for this example is the function module BAPI_HELPVALUES_GET. This function module provides the use of selection parameters, because it contains an import Table (SELECTION_FOR_HELPVALUES)
[C#]
static ArrayList getUserList(string sign, string option, string low, string high)
{
ERPConnect.R3Connection con = new R3Connection("SAPServer",00,"SAPUser","Password","EN","800");
ERPConnect.LIC.SetLic("xxxxxxxxxxxxx"); //Set your ERPConnect License.
con.Open(); //Open the connection to SAP.
RFCFunction func = con.CreateFunction("BAPI_HELPVALUES_GET");
func.Exports["OBJTYPE"].ParamValue = "USER";
func.Exports["METHOD"].ParamValue = "GETDETAIL";
func.Exports["PARAMETER"].ParamValue = "USERNAME";
RFCStructure shlp = func.Exports["EXPLICIT_SHLP"].ToStructure();
shlp["SHLPNAME"] = "USER_ADDR";
shlp["SHLPTYPE"] = "SH";
RFCStructure sfh = func.Tables["SELECTION_FOR_HELPVALUES"].AddRow(); ;
sfh["SELECT_FLD"] = "MC_NAMELAS";
sfh["SIGN"] = sign;
sfh["OPTION"] = option;
sfh["LOW"] = low;
sfh["HIGH"] = high;
func.Execute();
con.Close();
ArrayList user = new ArrayList();
for (int i = 0; i < func.Tables["HELPVALUES"].RowCount; i++)
{
user.Add(func.Tables["HELPVALUES"].Rows[i, 0]);
}
if (user.Count == 0)
{
user.Add("No results matching criteria");
}
return user;
}
For example we are going to display all users, whose name starts with M, on the console
[C#]
static void Main(string[] args)
{
ArrayList users = getUserList("I","CP","M*","");
foreach (object userdetail in users)
{
Console.WriteLine(userdetail);
}
Console.ReadLine();
}