0

I am trying to reset password for SAP system using BAPI but I am getting error

password is not type of field input

I am posting my code below.

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

String newPassword = getRandomString(); here it is giving error because getRandomString() is a user-defined function and I am unaware about this.

Is there any role of this while resetting password or can I directly use String newpassword=" ";?

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);
}

Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
MNW
  • 79
  • 2
  • 7
  • possible duplicate of [how to reset password in SAP using BAPI\_USER\_CHANGE?](http://stackoverflow.com/questions/22532803/how-to-reset-password-in-sap-using-bapi-user-change) – Eduardo Copat Mar 21 '14 at 19:17
  • You have asked the same question twice. Please, delete the other question. – Sully Mar 24 '14 at 08:41

2 Answers2

2

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");
vwegert
  • 18,371
  • 3
  • 37
  • 55
1

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

WiredCoder
  • 916
  • 1
  • 11
  • 39