[译]在SAP和LDAP数据库中搜索用户或在SAP中创建用户
By robot-v1.0
本文链接 https://www.kyfws.com/applications/search-user-in-sap-and-ldap-databases-or-create-us-zh/
版权声明 本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
- 6 分钟阅读 - 2948 个词 阅读量 0[译]在SAP和LDAP数据库中搜索用户或在SAP中创建用户
原文地址:https://www.codeproject.com/Articles/286938/Search-user-in-SAP-and-LDAP-databases-or-create-us
原文作者:snp157
译文由本站 robot-v1.0 翻译
前言
Use Bapi in C#
在C#中使用Bapi
介绍(Introduction)
SAP系统通常安装在大型公司办公室中.有时我们会犯一个错误,而一个用户可以有两个或多个登录名.当数据库很大时,我们如何找到这些重复项?如果使用CUA,并且CUA未与LDAP集成,则此程序适合您.我创建了这个程序来帮助自己工作.(SAP systems are usually installed in large corporate offices. Sometimes we can make a mistake and a user can have two or more logins. How can we find these duplicates when the database is large? If you use the CUA, and CUA is not integrated with LDAP, this program is for you. I have created this program to help myself in my work.)
在此发布的第一个版本只能搜索,创建用户,仅分配一个角色.现在,我添加了对用户角色的操作.(First version, published here, was capable only for search, create users, assign only one role. Now I added manipulation with user’s roles.)
使用代码(Using the code)
在安装此程序之前,确实存在一些先决条件需要满足:(There do exist some prerequisites which need to be fulfilled before you are to install this program:)
-
需要安装.NET 3.0,通常这已安装在PC中,从WinXP开始.(Need to install .NET 3.0, usually this is already installed in PCs, begin with WinXP.)
-
需要安装(Need to install)SAPGUI7.xx(SAPGUI7.xx)(这是针对SAP后端系统的SAP演示服务).((this is the SAP’s presentation service for SAP’s backend systems).) 在程序中,使用以下BAPI函数:(In the program, use the following BAPI functions:)
-
“(")
BAPI_USER_GETLIST
“(") -
“(")
BAPI_USER_GET_DETAIL
“(") -
“(")
BAPI_USER_CREATE1
“(") -
“(")
BAPI_USER_CHANGE
“(") -
“(")
BAPI_USER_UNLOCK
“(") -
“(")
BAPI_USER_LOCK
“(") -
“(")
RFC_READ_TABLE
“(") 可以使用SAP中的事务BAPI或在sapgui类型SE37->类型功能模块名称中浏览功能模块来获取对BAPI功能的导入/导出参数.这是一个如何锁定用户的示例:(Import/Export parameters to the BAPI functions can be obtained using the transaction BAPI in SAP or exploring the function module, in sapgui type SE37 -> type function module name. Here is an example of how can you lock the user:)
// input: user Login
public bool sapLockUser(string sUserLogin)
{
bool bOk = true;
if (sUserLogin == "") return false;
SAPFunctionsOCX.Parameter pUserName =
(SAPFunctionsOCX.Parameter)m_iBAPI_USER_LOCK.get_Exports("USERNAME");
((SAPFunctionsOCX.Parameter)pUserName).Value = sUserLogin;
bOk = m_iBAPI_USER_LOCK.Call();
if (bOk)
{
SAPTableFactoryCtrl.Tables tTables =
(SAPTableFactoryCtrl.Tables)m_iBAPI_USER_LOCK.Tables;
showReturn(ref tTables);
}
return bOk;
}
如果您在数据库中进行搜索,则需要在范围内进行搜索.在LDAP中,我们使用构造(If you get a search in database, you need to make a range area for searching. In LDAP we use construction)**反向波兰表示法(从右到左).(Reverse Polish Notation (from right to left).)**您可以在搜索语句中添加自己的构造.(You can add your own constructions in the search statement.)
(&(cn=?)(objectCategory=person)(mail=*)(userAccountControl=512))
在SAP的功能模块中,我们使用另一种技术来填充(In SAP’s function modules we use another technique where you need to fill the) SELECTION_EXP
结构体.您可以在事务BAPI的帮助中或SAP的文档中找到如何填写它:(structure. You can find how to fill it in the help in transaction BAPI, or in the SAP’s document:) SAP身份管理API(SAP Identity Management APIs) .(.)
如果(If the) import
功能模块中的参数是一个表,例如(parameter in function module is a table, as in the case of) SELECTION_EXP
,由于C#互操作和SAP的COM对象中存在编组错误,因此您需要使用包装函数.有许多方法可以解决此问题,如您所见,(, you need to use a wrapper function, because of the marshalling error in C# interop and SAP’s COM object. There are many ways to workaround this, as you can see in the blog of) Lim Bio Liong.(Lim Bio Liong.) 这里使用包装函数.(Here the wrapper function is used.)
SAPTableFactoryCtrl.Table oSELECTION_EXP =
(SAPTableFactoryCtrl.Table)tTables["SELECTION_EXP"];
int icntCol = oSELECTION_EXP.ColumnCount;
int icntRow = oSELECTION_EXP.RowCount;
icntRow = oSELECTION_EXP.RowCount;
sSapLogin = null;
try
{
oRowSetVal oRowSet = new oRowSetVal();
object oRow = ((SAPTableFactoryCtrl.Rows)oSELECTION_EXP.Rows).Add(null);
oRowSet.SetVal(ref oRow, "LOGOP", "AND");
oRowSet.SetVal(ref oRow, "ARITY", "1");
oRow = ((SAPTableFactoryCtrl.Rows)oSELECTION_EXP.Rows).Add(null);
oRowSet.SetVal(ref oRow, "PARAMETER", "USERNAME");
oRowSet.SetVal(ref oRow, "OPTION", "CP");
oRowSet.SetVal(ref oRow, "LOW", sapTemplateLogin.ToUpper());
}
在包装DLL中,我添加了一个新函数:(In the wrapper DLL I add a new function:) SetDateTime
.(.)
现在,idl说明如下:(Now the idl description looks like:)
interface IoRowSetVal : IDispatch{
[id(1), helpstring("method SetVal")]
HRESULT SetVal([in,out] VARIANT* pvRow, [in] BSTR vsColumn, [in] BSTR vsValue);
[id(2), helpstring("method SetDateTime")]
HRESULT SetDateTime([in,out] VARIANT* pvRow, [in] BSTR vsColumn, [in] VARIANT vVal);
};
程序中数据的结构(Structure of the data in the program)
首先,我必须说大多数程序的可能性是由数据结构决定的.该程序中的数据结构如下:(First of all, I have to tell that most program possibilities are determined by the data structure. The structure of the data in this program looks like:)
围绕此结构,可以创建用户界面来解决日常任务.(Around this structure the user interface is created to solve everyday tasks.)
从用户的角度来看这是如何工作的(How this work from user’s view)
首先,您需要在config选项卡中填充初始参数,如下所示:(First, you need to fill the config tab with initial parameters as here:)
第一次隐藏此选项卡.要获取它,您需要使用系统菜单取消隐藏:(First time this tab hidden. To get it you need to unhide using the system menu:)
填写"配置"选项卡时,可以从"面部"选项卡使用程序:(When you fill the config tab, you can work with program from face tab:)
可以在"姓氏"或” SAP用户登录"字段中键入搜索词.如果在SAP中找到登录名,则可以在"临时列表框"中查看它们.如果选中"具有角色"复选框,则也会加载分配给用户的所有角色.登录名可以存储在"内存"列表框中;由于在每个搜索过程中都会清除"临时列表"框.按” Enter"开始搜索:与按” Search"按钮相同.要搜索公司,可以在公司组合框中键入零件公司名称,然后按键盘上的” Enter”.(The searching words can be typed in ‘Last First Name’ or in ‘SAP User Login’ fields. If logins are found in SAP, they can be viewed in the Temporary ListBox. If checkbox ‘with roles’ is selected, then all roles assigned to the user are loaded too. Logins may be memorized in Memory list Box; because of Temporary list Box cleared in each search process. Press ‘Enter’ to start searching: it is the same as press ‘Search’ button. To search Company, you can type part company name in the Company ComboBox and press ‘Enter’ in the keyboard.)
我必须告诉我,使用内存中的用户和角色进行的所有操作,只有两个按钮才能更改SAP中用户的内容:面部选项卡上的黄色"更改/创建”,角色选项卡上的黄色"将用户保存在CUA中”,以及复选框"已阻止’更改状态用户的登录名:已阻止/未阻止!(I must tell that all manipulation with users and roles in memory and only two buttons change the content of the user in SAP: yellow ‘Change/Create’ on face tab and yellow ‘Save User in CUA’ in tab Roles, and checkBox ‘Blocked’ change the status user’s login: blocked/not blocked!)
找到登录名后,可以切换到tabRoles选项卡以查看角色或比较用户角色:(When you find logins, you can switch to tabRoles tab to view roles or compare user roles:)
可以在此处删除,添加或更改角色(仅在按"在CUA中保存用户"按钮时在SAP中保存!)(Roles can be deleted, added, or changed here (saved in SAP only when pressing button ‘Save User in CUA’!))
有时我需要将角色与其他用户进行比较:(Some times I need to compare roles with different users:)
如果在用户之间复制角色,则可以使用一组新角色保存所选用户.(If roles are copied between users, you can save the selected user with a new set of roles.)
我希望有人发现此实用程序有用.(I hope that somebody finds this utility useful.)
历史(History)
- 2011年11月20日:发布了第一版.(20.11.2011: First version published.)
- 2012年4月5日:发布了1.1.8版本.(04.05.2012: 1.1.8 version published.)
- 2012年5月17日:1.1.10版本. (较小的更改).(17.05.2012: 1.1.10 ver. (minor changes).)
- 24.05.2012:1.1.11(“比较用户的角色"标签中的次要更正).(24.05.2012: 1.1.11 (minor correction in compare user’s roles tab).)
- 07.09.2012:1.1.12(更正:角色UpperCase,Ldap筛选器未保存,一键比较两个登录名).(07.09.2012: 1.1.12 (Correct: Roles UpperCase, Ldap Filter not saved, compare two logins in one click).)
- 2013年5月15日:1.1.13(对于x64计算机,在编译中添加目标x86,更改LDAP <-> SAP电话和移动设备的映射)(15.05.2013: 1.1.13 (for x64 machines add target x86 in compilation, change mapping LDAP<->SAP telephone and mobile))
许可
本文以及所有相关的源代码和文件均已获得The Code Project Open License (CPOL)的许可。
C#3.0 C++ C# VC8.0 Vista .NET3.0 Windows WinXP COM SysAdmin 新闻 翻译