Receiving a list of all users English

From Theobald Software

Jump to: navigation, search

German Version: Liste aller Benutzer des SAP Systems


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)

static ArrayList getUserList(string sign, string option, string low, string high)
        { 
 
            ERPConnect.LIC.SetLic("xxxxxxxxxxxxx");
 
            R3Connection con = new R3Connection("hamlet",
                                                11,
                                                "user",
                                                "passw",
                                                "DE",
                                                "800");            
 
            con.Open();            
 
            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

static void Main(string[] args)
        {
            ArrayList users = getUserList("I","CP","M*","");
            foreach (object userdetail in users)
            {
                Console.WriteLine(userdetail);
            }
            Console.ReadLine();
        }

DeutschEnglish
Personal tools
Navigation
XtractQL Provider
Xtract RS