The above blog shows some structure and parameters of BAPI_USER_CREATE. Therefore, you need to call it in C # to clearly specify the parameters to be entered.
1. First reference the dll, and then start with the program: using SAP. Middleware. Connector;
2. The next step is to set the login parameters. Previous blog posts have described the following:
Public class MyBackendConfig: IDestinationConfiguration
{
Public RfcConfigParameters GetParameters (String destinationName)
{
If ("PRD_000". Equals (destinationName ))
{
RfcConfigParameters parms = new RfcConfigParameters ();
Parms. Add (RfcConfigParameters. AppServerHost, "192.168.1.3 ");
Parms. Add (RfcConfigParameters. SystemNumber, "00 ");
Parms. Add (RfcConfigParameters. User, "MENGXIN ");
Parms. Add (RfcConfigParameters. Password, "5239898 ");
Parms. Add (RfcConfigParameters. Client, "888 ");
Parms. Add (RfcConfigParameters. Language, "ZH ");
Parms. Add (RfcConfigParameters. PoolSize, "5 ");
Parms. Add (RfcConfigParameters. MaxPoolSize, "10 ");
Parms. Add (RfcConfigParameters. IdleTimeout, "60 ");
Return parms;
}
Else return null;
}
Public bool ChangeEventsSupported ()
{
Return false;
}
Public event RfcDestinationManager. ConfigurationChangeHandler ConfigurationChanged;
}
3. Set a method to reference the login parameter class:
Public void nco ()
{
IDestinationConfiguration ID = new MyBackendConfig ();
RfcDestinationManager. RegisterDestinationConfiguration (ID );
RfcDestination prd = RfcDestinationManager. GetDestination ("PRD_000 ");
RfcDestinationManager. UnregisterDestinationConfiguration (ID );
Nco (prd );
}
4. Then the call code is started. The following code is all released, and a line of description is displayed:
Public void nco (RfcDestination prd)
{
// Select the name of the BAPI to be called
RfcFunctionMetadata BAPI_COMPANYCODE_GETDETAIL_MD = prd. Repository. GetFunctionMetadata ("BAPI_USER_CREATE ");
// Create an "instance" that calls this BAPI"
IRfcFunction function = null;
Function = BAPI_COMPANYCODE_GETDETAIL_MD.CreateFunction ();
// Because the username is a field, you can directly assign it to the string.
Function. SetValue ("USERNAME", USERID. Text. Trim ());
// The next step is the password. Because the password is a structure with only one column, you can obtain the structure first.
Fcfcstructure PWD = function. GetStructure ("PASSWORD ");
// Set the content of this column in this structure
PWD. SetValue ("BAPIPWD", password. Text. Trim ());
// Pass the structure to the password parameter.
Function. SetValue ("PASSWORD", PWD );
// This is the login information and the type is also a structure, so the structure of this login information is obtained here
Fcirstructure logo = function. GetStructure ("LOGONDATA ");
// The following two values are the field values for setting the login structure.
Logos. SetValue ("GLTGV", "20110821 ");
Logos. SetValue ("GLTGB", "99991231 ");
// Upload the structure of the login information to LOGONDATA
Function. SetValue ("LOGONDATA", logo); // set parameters
// This is the address information, take the structure, assign a value, and then pass it in
Fcirstructure address = function. GetStructure ("ADDRESS ");
Address. SetValue ("FIRSTNAME", firstname. Text. Trim ());
Address. SetValue ("LASTNAME", lastname. Text. Trim ());
Address. SetValue ("DEPARTMENT", "Information Room ");
Function. SetValue ("ADDRESS", address); // sets the Parameter
// The following ults is the default account information, not required. We use it to set the language of the Logon account to ZH.
IRfcStructure DEFAULTS = function. GetStructure ("DEFAULTS ");
DEFAULTS. SetValue ("LANGU", "1"); // language code, corresponding to simplified Chinese
Function. SetValue ("DEFAULTS", DEFAULTS );
// The following is the RETURN, which is the structure of the RETURN result. Remember, here is different from above. above is Structure, and here is Table !!
IRfcTable returnStructure = function. GetTable ("RETURN ");
Function. Invoke (prd); // submit a call to BAPI
// The call result is displayed in the pop-up dialog box.
MessageBox. Show (returnStructure. GetString ("MESSAGE"). ToString ());
Prd = null;
}
5. The program running result is as follows:
6. log on to SAP, run SU01, input IT_XM01, and check the result:
Of course, if the user already exists and you still call this BAPI to generate the user, the system will be very interesting:
Use IT_XM01 to log on to the system. Everything is OK. The system status is as follows:
The newly created account has no permissions at all. You can call other bapis to add permissions to it !! The method is a bit different. You need to input a table as a parameter and release it in the next blog.