how to reset password in SAP using BAPI?

有些话、适合烂在心里 提交于 2019-12-07 13:20:28

问题


I am trying to reset password for SAP using bapi but i am getting error as "password is not type of field input".

I am posting my code below.

Here getRandomString() is user defined function. I have copied this code from Internet and I am unaware about this.

String newPassword = getRandomString();

try{
      JCO.Function bapiUserChange = repository.getFunctionTemplate("BAPI_USER_CHANGE").getFunction();
      if(bapiUserChange != null){
           JCO.ParameterList userChangeInput = bapiUserChange.getImportParameterList();

           JCO.Structure sPassword = userChangeInput.getStructure("PASSWORD");

           //sPassword.setValue(newPassword, ????) //what do I assign it to?

           userChangeInput.setValue(userId, "USERNAME");
           userChangeInput.setValue(newPassword, "PASSWORD");  // this gives an error
           userChangeInput.setValue("X","PASSWORDX"); //I know "X" is true, this will give an error too I believe

           mConnection.execute(bapiUserChange);

           //send E-mail
           boolean emailSent = sendEmail(userId, newPassword, "XXX200");
           msgMgr.reportSuccess("Password Reset Done");     

           if(mConnection != null){
                mConnection.disconnect();
           }

      }
}catch(Exception e){
     msgMgr.reportException("Could not change password " + e.getMessage(),true);
}

but String newPassword = getRandomString(); here it is giving error because getRandomString() is user defined function and i am unaware about this.Is there any role of this while reseting password or I can directly use String newpassword=" ";


回答1:


The parameter PASSWORD is typed as BAPIPWD which is a structure what in turn contains only a single field named BAPIPWD. Therefore, you need to access the structure approximately like this:

JCO.Structure sPassword = userChangeInput.getStructure("PASSWORD");
sPassword.setValue(newPassword, "BAPIPWD");



回答2:


Try using BAPIPWD or PASSWORD-BAPIPWD instead of PASSWORD, and just in case make sure the password is all caps



来源:https://stackoverflow.com/questions/22532803/how-to-reset-password-in-sap-using-bapi-user-change

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!